After Update

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have an AfterUpdate Event that doesn't seem to be working.

Private Sub Inspector_AfterUpdate()
On Error GoTo Err_Inspector_AfterUpdate

Me.InspectorPE = DLookup("PENumber", tblPENumber, Initials = "'" &
Me.Inspector & "'")

Exit_Inspector_AfterUpdate:
Exit Sub

Err_Inspector_AfterUpdate
MsgBox Err.Description
Resume Exit_Inspector_AfterUpdate

The idea is that it should automatically fill in the Inspector's PE Number,
but it does not. Even if I navigate away from the form and come back, it is
not entered in my control.
Any ideas?
Melinda
 
You have two typos in your DLookup that prevents it from returning any
values (it's probably returning a null). It should read

Me.InspectorPE = DLookup("PENumber", "tblPENumber", "Initials = '" &
Me.Inspector & "'")

1. The name of the table is string constant, not a variable, and should
therefore be enclosed in quotes

2. The criteria starts with the name of a field (not the contents of a
variable) and should therefore start the quote.
 
Hello,
I have an AfterUpdate Event that doesn't seem to be working.

Private Sub Inspector_AfterUpdate()
On Error GoTo Err_Inspector_AfterUpdate

Me.InspectorPE = DLookup("PENumber", tblPENumber, Initials = "'" &
Me.Inspector & "'")

Exit_Inspector_AfterUpdate:
Exit Sub

Err_Inspector_AfterUpdate
MsgBox Err.Description
Resume Exit_Inspector_AfterUpdate

The idea is that it should automatically fill in the Inspector's PE Number,
but it does not. Even if I navigate away from the form and come back, it is
not entered in my control.
Any ideas?
Melinda

It might help if you wrote the DLookUp correctly. :-)
EACH argument must be a string, not one string for all the arguments.

Me!InspectorPE = DLookup("[PENumber]", "tblPENumber", "[Initials] = '
" & Me!Inspector & " ' ")

The above assumes [Initials] is a Text datatype field.
Notice the placement of the double and single quotes.
I've added spaces to better show the single and double quotes in the
where clause. Remove those spaces when you write your code.

If [initials] is a Number datatype then use:

Me!InspectorPE = DLookup("[PENumber]", "tblPENumber", "[Initials] = "
& Me!Inspector)
 
Thanks, the first solution did it. I'm a novice at Visual Basic and I had
tried a code similar to that originally and it didn't work. I was missing
the brackets.
Thanks!
Melinda

fredg said:
Hello,
I have an AfterUpdate Event that doesn't seem to be working.

Private Sub Inspector_AfterUpdate()
On Error GoTo Err_Inspector_AfterUpdate

Me.InspectorPE = DLookup("PENumber", tblPENumber, Initials = "'" &
Me.Inspector & "'")

Exit_Inspector_AfterUpdate:
Exit Sub

Err_Inspector_AfterUpdate
MsgBox Err.Description
Resume Exit_Inspector_AfterUpdate

The idea is that it should automatically fill in the Inspector's PE Number,
but it does not. Even if I navigate away from the form and come back, it is
not entered in my control.
Any ideas?
Melinda

It might help if you wrote the DLookUp correctly. :-)
EACH argument must be a string, not one string for all the arguments.

Me!InspectorPE = DLookup("[PENumber]", "tblPENumber", "[Initials] = '
" & Me!Inspector & " ' ")

The above assumes [Initials] is a Text datatype field.
Notice the placement of the double and single quotes.
I've added spaces to better show the single and double quotes in the
where clause. Remove those spaces when you write your code.

If [initials] is a Number datatype then use:

Me!InspectorPE = DLookup("[PENumber]", "tblPENumber", "[Initials] = "
& Me!Inspector)
 
Back
Top