Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation against the query

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi

I have an entry form. On the save click i validate the data entered against teh data from another query. In order to access that query from within the form what techniques are available?

If anyone could give me a sample code, I'd be thankful!

Thanks

 
Try using the DLookup function.

varName = DLookup("Field1", "QueryName", "Criteria")

If anything includes embedded spaces, enclose it within square brackets (eg "[Last Name]").

If successful, DLookup will return the value of Field1 into varName. Field1 would need to be a field in your query.

QueryName is just the name of the query you want to search.

Criteria is like an SQL WHERE clause without the WHERE. As an example, assume you are looking for a query field called last name = "Smith" and that "Smith" is the value from a form text box called txtLastName. The criteria part would look like this: "[Last Name] = '" & txtLastName & "'". Note the single quotes around the textbox value. If you are using numeric data, remove them. If you are using date data, replace them with #.

So using our above example, here is how it would look:

varName = DLookup("Field1", "QueryName", "[Last Name] = '"
& txtLastName & "'")

You can save yourself some headaches by not naming fields and form controls with embedded spaces.

Good Luck!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top