SetFocus question

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

Guest

I have a textbox called "txtITEM_NO" that is a field in a table called
"tblMEAL_SUB". When a value is entered into the textbox, I have a DLookup in
VBA that executes and populates an unbound textbox with the matching item
description from a table called "tblITEM_MASTER". What I'd like to do is
this: If the value that is typed into "txtITEM_NO" is not in
"tblITEM_MASTER", then I'd like the focus to remain on "txtITEM_NO" and a
label to become visible indicating that the value is not found. Can someone
help me with this issue. Thanks in advance.
 
In the Before Update event of txtITEM_NO

Dim varItemDescr as Variant

varItemDescr = DLookup("[ITEM_DESCRIPTION]", "tblITEM_MASTER", _
"[ITEM_NO] = " & Me.txtITEM_NO)
If IsNull(varItemDescr) Then
MsgBox Me.txtITEM_NO & " Not Found"
Cancel = True
Else
Me.ITEM_DESCRIPTION = varItem
End If

I had to make up some of the names, but I think you will understand the
flow. The Cancel = True will cause the focus to stay in the field until a
valid item number is entered.
 
Thank you very much. I was using the wrong event property. It does look
very simple now that you've explained it to me.
--
Don Rountree


Klatuu said:
In the Before Update event of txtITEM_NO

Dim varItemDescr as Variant

varItemDescr = DLookup("[ITEM_DESCRIPTION]", "tblITEM_MASTER", _
"[ITEM_NO] = " & Me.txtITEM_NO)
If IsNull(varItemDescr) Then
MsgBox Me.txtITEM_NO & " Not Found"
Cancel = True
Else
Me.ITEM_DESCRIPTION = varItem
End If

I had to make up some of the names, but I think you will understand the
flow. The Cancel = True will cause the focus to stay in the field until a
valid item number is entered.

Don said:
I have a textbox called "txtITEM_NO" that is a field in a table called
"tblMEAL_SUB". When a value is entered into the textbox, I have a DLookup in
VBA that executes and populates an unbound textbox with the matching item
description from a table called "tblITEM_MASTER". What I'd like to do is
this: If the value that is typed into "txtITEM_NO" is not in
"tblITEM_MASTER", then I'd like the focus to remain on "txtITEM_NO" and a
label to become visible indicating that the value is not found. Can someone
help me with this issue. Thanks in advance.
 
Back
Top