String Not Working As Table Name - Access VBA -
<p>The beginning of the following code is supposed to get the BaseName of a file name in a textbox on a form and set it equal to a String "tblnewbid". The Debug.Print tblnew bid prints out the correct Table name exactly as it is supposed to. I verified the characters match exactly and there is an actual table that matches that name. </p>

<p>When I run the code I get error: Cannot find table or constraint. If I manually change tblnew to the actual table name, the code runs fine. Could it be that I need to Dim tblnewbid as something other than string?  </p>

<pre><code>Private Sub btnInsertRegions_Click()

DoCmd.Hourglass True  ' turn on Hourglass


Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim FSO As New FileSystemObject
Dim tblnewbid As String

Set db = CurrentDb
tblnewbid = FSO.GetBaseName(Me.txtFileName)


Debug.Print tblnewbid

db.Execute "ALTER TABLE tblnewbid ADD COLUMN O_StateRegion CHAR", dbFailOnError
db.Execute "ALTER TABLE tblnewbid ADD COLUMN D_StateRegion CHAR", dbFailOnError

Set rs = db.OpenRecordset("Select [OriginState] from [tblnewbid];")

rs.MoveFirst

    strSQL = "UPDATE [tblnewbid] INNER JOIN [tblStates]"
    strSQL = strSQL &amp; " ON [tblStates].[StateAbbrev] = [tblnewbid].[OriginState]"
    strSQL = strSQL &amp; " SET [tblnewbid].[O_StateRegion]=[tblStates].[StateRegion]"


    db.Execute (strSQL), dbFailOnError


rs.MoveFirst

    strSQL = "UPDATE [tblnewbid] INNER JOIN [tblStates]"
    strSQL = strSQL &amp; " ON [tblStates].[StateAbbrev] = [tblnewbid].[DestinationState]"
    strSQL = strSQL &amp; " SET [tblnewbid].[D_StateRegion]=[tblStates].[StateRegion]"


    db.Execute (strSQL), dbFailOnError

rs.Close

Set rs = Nothing
</code></pre>