I keep getting a compile error on Dim MyDB as Database. I've even tried adding as DAO.Database but that doesn't seem to correct the problem. What am I doing wrong?
Private Sub cmdAddNew_Click()
Dim MyDB As dao.database, rcsTest As Recordset
'MsgBox "The Code is Executing!"
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set rcsTest = MyDB.OpenRecordset("tblTest")
If Nz([cboApplication], "") = "" Or Nz([cboDescription], "") = "" Or Nz([txtVolume], "") = "" Or Nz([txtMailDate], "") = "" Then
MsgBox "You must complete all fields!", vbCritical, "Incomplete Record!"
Exit Sub
End If
rcsDocControl.AddNew
rcsDocControl![Application] = Forms![frmAddNewDoc]![txtDoc_ID]
rcsDocControl![Description] = Forms![frmAddNewDoc]![txtTitle]
rcsDocControl![Volume] = Forms![frmAddNewDoc]![txtRevision]
rcsDocControl![Mail_Date] = Forms![frmAddNewDoc]![txtDate_Added_DB]
rcsDocControl.Update
MsgBox "The Document has been Added!", vbDefaultButton1, "Document Added!"
cboApplication = ""
cboDescription = ""
txtVolume = ""
txtMailDate = ""
Exit_cmdAddNew_Click:
Exit Sub
Err_cmdAddNew_Click:
Select Case Err.Number
Case 3022
MsgBox "You have already added this controlled document (Document ID already in the database).", vbCritical, "Error!"
Exit Sub
Case Else
MsgBox Err.Description & " " & Err.Number
Resume Exit_cmdAddNew_Click
End Select
End Sub
Private Sub cmdAddNew_Click()
Dim MyDB As dao.database, rcsTest As Recordset
'MsgBox "The Code is Executing!"
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set rcsTest = MyDB.OpenRecordset("tblTest")
If Nz([cboApplication], "") = "" Or Nz([cboDescription], "") = "" Or Nz([txtVolume], "") = "" Or Nz([txtMailDate], "") = "" Then
MsgBox "You must complete all fields!", vbCritical, "Incomplete Record!"
Exit Sub
End If
rcsDocControl.AddNew
rcsDocControl![Application] = Forms![frmAddNewDoc]![txtDoc_ID]
rcsDocControl![Description] = Forms![frmAddNewDoc]![txtTitle]
rcsDocControl![Volume] = Forms![frmAddNewDoc]![txtRevision]
rcsDocControl![Mail_Date] = Forms![frmAddNewDoc]![txtDate_Added_DB]
rcsDocControl.Update
MsgBox "The Document has been Added!", vbDefaultButton1, "Document Added!"
cboApplication = ""
cboDescription = ""
txtVolume = ""
txtMailDate = ""
Exit_cmdAddNew_Click:
Exit Sub
Err_cmdAddNew_Click:
Select Case Err.Number
Case 3022
MsgBox "You have already added this controlled document (Document ID already in the database).", vbCritical, "Error!"
Exit Sub
Case Else
MsgBox Err.Description & " " & Err.Number
Resume Exit_cmdAddNew_Click
End Select
End Sub