Question:
How can I program Access to run an SQL SELECT query within VB code in the Access file?
a link to the past
2007-02-21 18:41:35 UTC
When a user clicks a button on a MS Access form, VBA code runs to generate a SQL SELECT query. This SQL SELECT query should then run to display the results in a table. It looks like this:

Dim SQL As String
SQL = GenerateSQLFromForm
' here is where the code should execute the SQL
Three answers:
anonymous
2007-02-21 20:09:17 UTC
You can assign a macro to the button's onclick event.



1. Create a query that stores your SQL statement

2. Create a macro

3. Assign to the macro the RunQuery action

4. Select the query you created

5. In your form, select the macro as the button's onclick event action.
mcmickle
2016-10-16 09:18:20 UTC
Do you recommend a kind in MS-get right of entry to? if so, then generally provide the administration concentration and then examine or write the right property. Examples: 'to show hi in a text textile field named txt100 Me.txt100.SetFocus Me.txt100.text textile = "hi" 'under is an occasion SUB to set the backcolor of a label 'the label shade could be expressed as a kind Sub setBackColor(ctl As Label, lngColor As long) Dim myColor As long Dim myControl As Label myColor = lngColor Set myControl = ctl myControl.BackColor = myColor Set myControl = no longer something end Sub i wish that this helps!
Serge M
2007-02-22 00:34:09 UTC
If your query is not SELECT statement, you can use



DoCmd.RunSQL SQL



Otherwise, use recordset (cursor) for further work, for example,



Dim rst AS Recordset

set rst = currentdb.openrecordset(SQL)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...