A
a24t42
In my database, I have 4 forms that all have the following code
attached to a command button.
----------------------
Private Sub cmdSave_Click()
Dim testmsg As Integer
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase("D:\SouthEastern\STC_Stock\Stock.mdb")
Set rs = db.OpenRecordset("Counter", dbOpenDynaset)
'Increment the counter by 1
rs.Edit
rs!NextNumber = rs!NextNumber + 1
rs.Update
'Save the record
DoCmd.RunCommand acCmdSaveRecord
'Message Box
testmsg = MsgBox("Do you want to add another Record?", 4, "Question?")
'Add another record
If testmsg = 6 Then
DoCmd.GoToRecord , , acNewRec
Me![Date_Rcd].SetFocus
Else
DoCmd.Close
End If
End Sub
----------------------------------------------
My question is about the 'set db' line. It is requiring that I put in
the full path to the database. If I put just "Stock.mdb" I get an
error message. The code is working fine. My problem is if I move the
database to another computer, I manaully have to change the 'set db'
line on all 4 forms. Is there a way to declare it only once? Or is
there just a better way?
Thanks in advance.
attached to a command button.
----------------------
Private Sub cmdSave_Click()
Dim testmsg As Integer
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase("D:\SouthEastern\STC_Stock\Stock.mdb")
Set rs = db.OpenRecordset("Counter", dbOpenDynaset)
'Increment the counter by 1
rs.Edit
rs!NextNumber = rs!NextNumber + 1
rs.Update
'Save the record
DoCmd.RunCommand acCmdSaveRecord
'Message Box
testmsg = MsgBox("Do you want to add another Record?", 4, "Question?")
'Add another record
If testmsg = 6 Then
DoCmd.GoToRecord , , acNewRec
Me![Date_Rcd].SetFocus
Else
DoCmd.Close
End If
End Sub
----------------------------------------------
My question is about the 'set db' line. It is requiring that I put in
the full path to the database. If I put just "Stock.mdb" I get an
error message. The code is working fine. My problem is if I move the
database to another computer, I manaully have to change the 'set db'
line on all 4 forms. Is there a way to declare it only once? Or is
there just a better way?
Thanks in advance.