SQL in Form

A

Ashish Nanda

How would i run a SQL query in a form.
I just want to run the query in my MS Access application
and its a simple select query and i want to display this
result on a messagebox.
Can someone send me the code,
Best Regards,
Ashish Nanda
 
C

Chris

How are you using the query?

Is it the data source of the form? If so, enter the
query name in the form's "Row Source".

Is it to send a messagebox answer to the user based on a
field entry, change event, etc? The process below loops
through the data in the query and would send a message
box for each record. Just exit when you reach a value or
some other parameter.

*********************************************
Dim strName As String
Dim strSuper As String
Dim strAccess As String

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "[queryname]", CurrentProject.Connection,
adOpenForwardOnly, adLockOptimistic

With rst
.MoveFirst
Do Until rst.EOF
strName = !Name
strSuper = !SUPERVISOR
strAccess = !AccessLevelID
rst.MoveNext
Loop
MsgBox "The data as follows: " & strName &
strSuper & strAccess ,vbCritical, gblTitle
End With
***************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top