Onchange event not working

T

trekgoes2malaysia

I am trying to update a field (txtcount) on a form everytime another
field (dateid) on my form changes. I am using the OnCHange event to
do this but I can't seem to get access to read the event VBA code let
alone actually perform the update on the desired field when dateid
changes. I have included my code below. Any help is really
appreciated.

Private Sub dateid_Change()

Dim stQueryName As String
Dim getcount As Integer

stQueryName = "workoutcount"
sql = "[athleteid] = " & Me![Athleteid] & " and " & " [dateid] =
" & Me![dateid]

getcount = DLookup("[Count Of log]", stQueryName, sql)
Me!Txtcount.Value = getcount

End Sub
 
A

Allen Browne

The Change event is not suitable for what you want. It fires for each
keystroke (and you must use the Text property as the Value is not yet up to
date.)

If the user is typing into dateid, use its AfterUpdate event procedure.

Also, the count in the query will not be right until this record is saved.
 
T

trekgoes2malaysia

THanks Allen. I tried your suggestion but even the afterupdate event
did not work. The dateid field I am referring to is a list box. I
have several controls on the form that toggle the dateid field from
one list item to the next (one date to another) so the user never
actually needs to click on the list box (its locked any). ANy other
suggestions on how I might be able to solve this without attaching my
VBA code to every control that changes the date items (i.e. next,
previous, new controls)??.
 
B

Bob Quintal

(e-mail address removed) wrote in
THanks Allen. I tried your suggestion but even the afterupdate
event did not work. The dateid field I am referring to is a list
box. I have several controls on the form that toggle the dateid
field from one list item to the next (one date to another) so the
user never actually needs to click on the list box (its locked
any). ANy other suggestions on how I might be able to solve this
without attaching my VBA code to every control that changes the
date items (i.e. next, previous, new controls)??.

You must already have code in each of those controls (to manipulate
the listbox)? Just rename your sub to a name that's not an event,
and add the name into each of those controls on a new line above the
exit_sub or end sub statements

I am trying to update a field (txtcount) on a form everytime
another field (dateid) on my form changes. I am using the
OnCHange event to do this but I can't seem to get access to read
the event VBA code let alone actually perform the update on the
desired field when dateid changes. I have included my code
below. Any help is really appreciated.

Private Sub dateid_Change()

Dim stQueryName As String
Dim getcount As Integer

stQueryName = "workoutcount"
sql = "[athleteid] = " & Me![Athleteid] & " and " & "
[dateid] =
" & Me![dateid]

getcount = DLookup("[Count Of log]", stQueryName, sql)
Me!Txtcount.Value = getcount

End Sub
 
A

Allen Browne

Use the event where the user *does* interact.

The controls' events do not fire if the *user* does nothing there.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

THanks Allen. I tried your suggestion but even the afterupdate event
did not work. The dateid field I am referring to is a list box. I
have several controls on the form that toggle the dateid field from
one list item to the next (one date to another) so the user never
actually needs to click on the list box (its locked any). ANy other
suggestions on how I might be able to solve this without attaching my
VBA code to every control that changes the date items (i.e. next,
previous, new controls)??.

I am trying to update a field (txtcount) on a form everytime another
field (dateid) on my form changes. I am using the OnCHange event to
do this but I can't seem to get access to read the event VBA code let
alone actually perform the update on the desired field when dateid
changes. I have included my code below. Any help is really
appreciated.

Private Sub dateid_Change()

Dim stQueryName As String
Dim getcount As Integer

stQueryName = "workoutcount"
sql = "[athleteid] = " & Me![Athleteid] & " and " & " [dateid] =
" & Me![dateid]

getcount = DLookup("[Count Of log]", stQueryName, sql)
Me!Txtcount.Value = getcount

End Sub
 
R

rquintal

THanks Allen. I tried your suggestion but even the afterupdate event
did not work. The dateid field I am referring to is a list box. I
have several controls on the form that toggle the dateid field from
one list item to the next (one date to another) so the user never
actually needs to click on the list box (its locked any). ANy other
suggestions on how I might be able to solve this without attaching my
VBA code to every control that changes the date items (i.e. next,
previous, new controls)??.

You must already have code in each of those controls (to manipulate
the listbox)? Just rename your sub to a name that's not an event, and
add the name into each of those controls on a new line above the
exit_sub or end sub statements

Q

I am trying to update a field (txtcount) on a form everytime another
field (dateid) on my form changes. I am using the OnCHange event to
do this but I can't seem to get access to read the event VBA code let
alone actually perform the update on the desired field when dateid
changes. I have included my code below. Any help is really
appreciated.
Private Sub dateid_Change()
Dim stQueryName As String
Dim getcount As Integer
stQueryName = "workoutcount"
sql = "[athleteid] = " & Me![Athleteid] & " and " & " [dateid] =
" & Me![dateid]
getcount = DLookup("[Count Of log]", stQueryName, sql)
Me!Txtcount.Value = getcount
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top