Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dim Database ???

Status
Not open for further replies.

tbassngal

Programmer
Feb 18, 2003
74
0
0
US
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

 
Have it figured out, I was missing the reference - don't know how to delete the thread, sorry! Missing DAO 3.6
 
If you want to "delete" the thread, you can just red-flag your original post (look for "Inapproproate post? If so, Red Flag it!") just below your original post.

Glad you got it sorted out.

By the way, you must be using Access 2003, my guess anyway. Once you go to '07 and/or '10, you won't have to worry about the DAO reference, it's in there by default.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top