Macro problem

seirra

Board Regular
Joined
Nov 7, 2002
Messages
72
:rolleyes: Good day, :rolleyes:
Back ground: I’m working on a database that tracks packaging contents and assigns a number to them. The package number is just the simple auto number and the year so, 1/2004, 2/2004 and so on. The only part I haven’t figared out is having the user have the database to another location at the end of the year by pressing a button on the form they use.
1) I haven’t sorted out yet is the creating a new database until I saw bat17’s post with this code:

Function CreateNewDB()
Dim wrk As Workspace
Dim dbNew As Database
Dim strName As String
Dim strDefault As String

strDefault = "Accounts" & Format(DATE, "YYYYMMDD")
strName = InputBox("Enter name for new Database", "Database Name", strDefault)
If strName = "" Then Exit Function ' action canceled
Set wrk = DBEngine.Workspaces(0)
Set dbNew = wrk.CreateDatabase("C:\My Documents\" & strName & ".mdb", dbLangGeneral, dbEncrypt)
Set dbNew = Nothing
End Function
But once I input the code in Access 2000 on Windows 2000 and XP pro I get the following error message

:eek: Compile error :
Ambiguous name detected : CreateNewDB

2) How do I go about changing the same location from something changeable by a user. I would love to be able to do this in a text box on a form where they enter the rest of the information.

Thanks in advance
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Ambiguous name detected : CreateNewDB

You must have other code callled this somewhere.

Do a search for CreateNewDB and check Current Database.
 
Upvote 0
Dont call the module the same name as the function!

Function CreateNewDB()
Dim wrk As Workspace
Dim dbNew As Database
Set wrk = DBEngine.Workspaces(0)
Set dbNew = wrk.CreateDatabase(Forms![MyForm]![txtPath] & Forms![MyForm]![txtName] & ".mdb", dbLangGeneral, dbEncrypt)
Set dbNew = Nothing
End Function

Where MyForm is the name of your Form, txtPath is the text box with the path and txtName is the txtbox with the name for the DB.

You will probably need to add some error checking to make sure that you end up with a valid path/name though.

Peter
 
Upvote 0

Forum statistics

Threads
1,221,773
Messages
6,161,855
Members
451,724
Latest member
sledparty

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top