Help with code?

gMAC

Registered User.
Local time
Today, 02:33
Joined
Dec 21, 2001
Messages
29
I found this code (thanks to this forum) and it works great!

Sub CreateNewDB()
Dim wsp As Workspace
Dim dbs As Database
Dim strDBFile As String
strDBFile = "C:\NewDB.mdb"
Set wsp = DBEngine.Workspaces(0)
Set dbs = wsp.CreateDatabase(strDBFile, dbLangGeneral)
DoCmd.CopyObject strDBFile, , acTable, "Table1"
dbs.close
Set dbs = Nothing
Set wsp = Nothing
End Sub

I have a button on my form (Send), that runs a make table query, then runs this code. I would like for it to name the new database with the customer job number. Something like this C:\(Me.MyFormField).mdb. But I'm not sure how to write this part.

Thanks gMAC
 
This is where the DB is named
strDBFile = "C:\NewDB.mdb"

So if you substatute your name for NewDB, that should do it.
Lets say you put the the name you want in a STRING variable called FileName, you would need to construct the this line as such:
strDBFile = "C:\" & FileName & ".mdb"

But you better make sure it is a valid FileName or it will error.
 
Hello,

Try this

Replace strDBFile = "C:\NewDB.mdb" with

strDBFile = "C:\" & Me.MyFormField & ".mdb"

:)
-Osiris
 
Thanks, I'll give it a try.
gMAC
 

Users who are viewing this thread

Back
Top Bottom