Checking that a record exists in a different table

Mr Clevver

Idiot Savant
Local time
Today, 18:10
Joined
Jun 26, 2008
Messages
17
Hi, I hope you might be able to help me with a little issue I’m having with an order processing system I’m trying to put together

Firstly a little info about what I’m trying to achieve:
I have a form which lists products within an order, and I’m currently trying to write some code that will, upon exiting a textbox [ISBN13] check whether the value within said textbox matches any records in a table [tProducts] and produce separate results depending on the outcome. If the product does not exist it will jump to a form to allow the user to add a new product record; if there is one entry it will run an SQL query to add that product to the table [tOrderlines] and refresh the form; if there are multiple entries it will produce a form in which the user can select one of the matching products from a listbox and then have that added to the table [tOrderlines].

I understand somewhat the use of If Else clauses, and am confident I should be able to do that and create the necessary forms/SQL statements, however I am utterly stuck with the ‘checking whether a record exists which matches the value in the textbox’ part.

 
Last edited:
You can use the Dcount function

e.g.

If Dcount("ColumnToCount","TableToCount","PrimaryKey=" & ValueFromTextBox) > 0 then

You have at least one record with that Primary Key

Dont forget to substitute your column/table/primarykey names in the above
 
Thanks, that seems to have worked a treat. Would have never have thought it would have been something so simple.

Thanks again.
 

Users who are viewing this thread

Back
Top Bottom