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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running SELECT statement in VBA

Status
Not open for further replies.

bishman

Programmer
Jun 29, 2003
9
0
0
GB
I have an Access form where a user enters a value into a text field. I can get this value through VBA no problem.

However, I want to run a check on this value.

How can I run a SELECT statement in VBA code. What I want to do is the following:

SELECT COUNT(Records) FROM Table WHERE Records = "Value user entered in the form"

Then I need to check if count is zero, and if so, display an error message.

Any ideas?
Many thanks.
 
Hi bishman,

For this use DCOUNT rather than SELECT ..

Code:
RecCount = DCOUNT("Records","Table","Records =" & UserInput)

Enjoy,
Tony
 
Hello,

To run SQL from code use DoCmd.RunSQL "SQLSTRING".

Regards,

Bitbuster
 
Hi Bitbuster,

RunSQL is for Action queries only (INSERTs, ALTERs etc.), not SELECTs.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top