SQL in Form

  • Thread starter Thread starter Ashish Nanda
  • Start date Start date
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
 
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
***************************************************
 
Back
Top