Restrict Entry in Textbox

Skip Bisconer

Who Me?
Local time
Today, 08:18
Joined
Jan 22, 2008
Messages
285
This has probably been answered before but I don't know the key words to get a search.

I have a form textbox that updates a table. I would like to have something like a rowsource without the combobox to make sure a number doesn't get to the table unless it is in a field found in a specific query. Is there a way to do that?
 
In the textbox BeforeUpdate event you can use the DLookup() function to see whether the value already exists. If it does, do nothing and let the data entered stand, if it doesn't, use Cancel = True which will cause the cursor to stay in the textbox and use a message box to inform the user of their mistake and have them take corrective action.
 
Thanks for the response

I guess I don't have a handle on this as I get a Compile Syntax error with this On Enter Event module

Where OEOO_ORDR is a field in the referenced query. I am trying to make sure the form OEOO_ORDR entry is located in the query OEOO_ORDR field.

Maybe you can point out the errors of my ways

Code:
Private Sub OEOO_ORDR_Enter()
'For numerical values:
        DLookup("OEOO_ORDR", "qryTotalInvoiceOrderLines", "Criteria = " & forms!frmSelectOrders!OEOO_ORDR)
End Sub
 
The OnEnter event is not the appropriate place! You might try the textbox BeforeUpdate event, as I suggested.

Also, unless you actually have a field named Criteria, you have to replace this with the name of the field.
 
I get a an entry error "Expected: =" and when I try compile I get a Syntax Error all on the Dlookup

Code:
Private Sub OEOO_ORDR_BeforeUpdate(Cancel As Integer)
DLookup("OEOO_ORDR", "qryTotalInvoiceOrderLines", "OEOO_ORDR="  & forms!frmSelectOrders!OEOO_ORDR)
 
'To maintain a constant date to post to table
DeliveryDate = txtDate
'Counts the nuber of order numbers entered
txtRecCount = txtRecCount + 1
 
End Sub
="
 
Last edited:

Users who are viewing this thread

Back
Top Bottom