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

Opening a table

Status
Not open for further replies.

coughnut

Programmer
Dec 6, 2005
27
US
Hi, I am trying to open a table that has been named by the user. The name of the table is in a string called tableName.
When I run this part of my code I get an error saying that the table does not exist. But I see that the table is there, but why can't I open it. Thank you.

here is my code:

Set conDatabase = CurrentProject.Connection
strSQL2 = "SELECT * FROM tableName"
rs2.Open strSQL2, conDatabase, adOpenDynamic, adLockOptimistic
 
Try concatenating the value into the string

[tt]strSQL2 = "SELECT * FROM " & tableName
' or
strSQL2 = "SELECT * FROM [" & tableName & "]"[/tt]

one will often see string variables prefixed with str, to avoid ambiguous names... (strTableName?)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top