Making Table in Back End mdb

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to make a table in the back end when the path to the back end is
not always the same. The path is always saved in a table. Have tried using
the RunSql and using string for path but does not seem to work. Have tried
referencing path from field on form, half works! Gets half the path and then
adds on the reference to the field. Is it possible to use strings or
references in SQL?
Many thanks
 
You have to set a reference to the relevant database.
Dim dbX As Database
Dim sPath As String
Dim sSQL As String

sPath = DLookup("[DBPath]", "tblMyTable")
If Len(Trim(sPath)) > 0 Then
Set dbX = DBEngine(0).OpenDatabase(sPath)

sSQL = "CREATE TABLE myTable (ID LONG PRIMARY KEY NOT NULL,
myintfield INTEGER)"
dbX.Execute sSQL, dbFailOnError

dbX.Close
Set dbX = Nothing
End If

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
You can also do it this way:
CurrentDb.Execute "CREATE TABLE [C:\MyDB.mdb].myTable (ID LONG PRIMARY
KEY NOT NULL, myintfield INTEGER)"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top