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

Calling a query

Status
Not open for further replies.

TheCandyman

Technical User
Sep 9, 2002
761
0
0
US
I need some help on how to call a stored query. If that's not possible call a Macro. I can't seem to find any examples.
 
Hi -

In what context do you need the query - do you want it to appear when a user hits a button, open as a recordset, etc? Somebody should be able to help.

- CJ
 
It's in my coding, i want to call a query from code.

....
....
With adoCmd
.ActiveConnection = adoConn
.CommandText = strSQL
.CommandType = adCmdText
.Execute , , adExecuteNoRecords
End With
adoConn.CommitTrans

Set adoRst = Nothing
Set adoCmd = Nothing
Set adoConn = Nothing
*********** Want to call Query Here ***************
Call Command9_Click
End Sub
 
DoCmd.RunSQL "Select [FIELDS], From
Where [CRITERIA];"
 
How do i open up an existing query, not make a new SQL statement??

If i do make an SQL statment, how do i diplay the results in a Datasheet?
 
If you use the wizard to create command button (on the tool box, make sure the control wizards toggle is selected and add a command button to the form), chose Miscellaneous as the category and Run Query as the action. It will prompt you to select the query you would like to run and the code that is generated looks like this:

Code:
Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

    Dim stDocName As String

    stDocName = "qry NOTE: New Product"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command1_Click:
    Exit Sub

Err_Command1_Click:
    MsgBox Err.Description
    Resume Exit_Command1_Click
    
End Sub

The wizard is a good way to see how some things are done if you are new to the game.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top