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

SQL Error - missing operator

Status
Not open for further replies.

dalex17

Technical User
Jul 14, 2002
96
US
Hello,

Can someone tell me how I can assign a SQL command to a button on a form? I know how to assign a VBA command to a button, but not SQL command to a button. Can someone please orient me.

Thanks!

 
you can use the docmd. for example

DoCmd.RunSQL "SELECT username FROM user;"

You would run that on the OnClick Event of the button.

HTH Dave
ToeShot@Hotmail.com
Today Is Tomorrows Yesterday. So Why Wait
 
ToeShot: DoCmd.RunSQL will generate error number 2342 for Select statements. You can use it only for action queries...

Dalex17's post is a little ambiguous...What exactly is needed?

As a general example:

Sub CommandCutton_Click()
Dim strSQL$
Dim rst As DAO.Recordset
strSQL = "Select * From TableName;"
'now you do whatever you want with the SQL:
RecordSource = strSQL
CurrentDb.QueryDefs("AnyQueryName").SQL = strSQL
Set rst = CurrentDb.OpenRecordset(strSQL)
End Sub

Regards, [pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top