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

MS ACCESS VB to run query

Status
Not open for further replies.

Scunningham99

Programmer
Sep 20, 2001
815
0
0
GB
Hi All

I have a label on my ms access form whereby i would like to execute a command to run SQL on click event.


Dim mydb As Database 'database
Dim myrs As Recordset 'table to search

Dim TableSource As String
Dim searchfield As String
Dim searchstring As String
Dim SQL As String


Set mydb = CurrentDb

TableSource = "tblcompany"
searchfield = "[Customer Forename]"
searchstring = "Mary"

'put conditions in where clause for search criteria set to variables

SQL = "Select * from " & TableSource

Set myrs = mydb.OpenRecordset(SQL) 'table to read from"

End Sub

I CANNOT GET THE ABOVE TO RUN/COMPILE WHEN I CHANGE TO '*' FOR A COLUMN NAME. SUCH AS REPLACING IT WITH SEARCHFIELD IE & "[" & searchfeld "]" &

Any help would be greatly appreciated!!

I WOULD LIKE TO POSSIBLE POBULATE THE RESULTS IN TO TEXT BOXES ON FORM!

 
Would you show some code with the searchfield that that you've tried to use?
 
Replacing:-- SQL = "Select * from " & TableSource

with


SQL = "Select [" & searchfield "]" & " from " & TableSource

it executes, but when i try and click on the button is says the event may not represent an expresion, or macro l=bla bla bla.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top