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

SQL Code to Look for Table?

Status
Not open for further replies.

jt463

IS-IT--Management
Nov 23, 2005
134
I want to just use one form and store a table name in an invisible field so I don't have to create many different forms.

In other words, I have Form1 with InvisField (which stores the name of the table that I want to submit the records to). So if I have Table1 in the InvisField, I am trying to figure out the VB that will allow me to change the SQL to look at the InvisField data and open that table accordingly.

This is what I have:

Code:
Dim tbldb as DAO.Database
Dim tblrst as DAO.Recordset
Dim TableString As String

TableString = Me.InvisField.Value

Set tbldb = CurrentDb
Set tblrst = tbldb.OpenRecordset("select * from '" & TableString & "' WHERE ...")

Basically, I am trying to figure out how I can pass the table name from the form to the select statement.

Any help would be greatly appreciated!
 



Hi,

You're close. No quotes around table value...
Code:
Set tblrst = tbldb.OpenRecordset("select * from " & TableString & " WHERE ...")


Skip,

[glasses] When a wee mystic is on the loose..
It's a Small Medium at Large! [tongue]
 
Genius!

Thanks Skip!
 

Brackets should be safer though!

Set tblrst = tbldb.OpenRecordset("select * from [" & TableString & "] WHERE ...")

for table names like This Is My Table Name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top