How to run a query from a form (1 Viewer)

davidg47

Registered User.
Local time
Today, 02:48
Joined
Jan 6, 2003
Messages
59
I have a query that I wrote that searches several tables for an employees work ID number. The query works GREAT! But now I want to build a form with a search button that when clicked will run the query and if it finds the employee in any of the tables, it will return the requested fields on the form. If it doesn't find anything, it will send a MsgBox that says "Not Found!"

Any ideas on how to go about this?

Is this even the right place for me to ask this question?

Thanks,
David
 

KeithG

AWF VIP
Local time
Yesterday, 23:48
Joined
Mar 23, 2006
Messages
2,592
Create a function that opens up a recordset with your SQL and retrieves the data. Can you post you SQL? what is then name of your form and textbox?
 

davidg47

Registered User.
Local time
Today, 02:48
Joined
Jan 6, 2003
Messages
59
OK, here is the Query that I have been running from the Query Analyzer in SQL Server 2000. I now want to build a form that will run this query by clicking on a Search button on the form. If it finds the ID Number, then it will populate the fields I have requested in the Query... if it doens't, it will return a MsgBox saying, "Not Found!"


SELECT companyname, locationcode, locationdesc, statecode
FROM master1800flowers
WHERE ID = '111';
SELECT companyname, locationcode, locationdesc, statecode
FROM master24hourfitness
WHERE id = '222';
SELECT companyname, locationcode, locationdesc, statecode
FROM masteracmebrick
WHERE id = '333';
SELECT companyname, locationcode, locationdesc, statecode
FROM masteraep
WHERE id = '444';
SELECT companyname, locationcode, locationdesc, statecode
FROM masterallied
WHERE id = '555'

I do not know how to create a function that opens a recordset.

Thanks so much for your help...
D
 

KeithG

AWF VIP
Local time
Yesterday, 23:48
Joined
Mar 23, 2006
Messages
2,592
Are you using msAccess or SQl Server?
 

davidg47

Registered User.
Local time
Today, 02:48
Joined
Jan 6, 2003
Messages
59
I am using MSAccess as the front end to a SQLServer2000 DB. And as you know, the tables are reflected in the tables when you open Access.
 

davidg47

Registered User.
Local time
Today, 02:48
Joined
Jan 6, 2003
Messages
59
The tables in my MS Access application are linked to tables in SQL Server 2000.
 

Users who are viewing this thread

Top Bottom