Hi all,
I have a database that I am trying to recreate from an old one and have taken my code to use on a new form. I believe the problem is that my code is not executing since I have now included a message box. When I click on the button, I get nothing. Nothing happens. I did some searching and found that with MS Access 2007, you should be able to compile forms so that Access can determine where there might be errors but when I try to compile in the VB menu, the option is dimmed out. Additionally, I hear there is a requirement to "enable code" but when I try to view the URL for help from this forum, it never loads. My on-click event for the button does say "event procedure" and when I go to view the code, it takes me right to the procedure but then again, I don't have any other procedures in this database yet. Can you please help!!
I am trying to add the entries of an unbound form into a table.
Private Sub cmdAddNew_Click()
On Error GoTo Err_cmdAddNew_Click
Dim MyDB As Database, rcsDocControl As Recordset
MsgBox "The Code is Executing!"
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set rcsDocControl = MyDB.OpenRecordset("tblDocControl")
If Nz([txtDoc_ID], "") = "" Or Nz([txtTitle], "") = "" Or Nz([txtRevision], "") = "" Or Nz([txtDate_Added_DB], "") = "" _
Or Nz([cboType], "") = "" Or Nz([cboOwner], "") = "" Or Nz([URL_Location], "") = "" Then
MsgBox "You must complete all fields!", vbCritical, "Incomplete Record!"
Exit Sub
End If
rcsDocControl.AddNew
rcsDocControl![Doc_ID] = Forms![frmAddNewDoc]![txtDoc_ID]
rcsDocControl![Title] = Forms![frmAddNewDoc]![txtTitle]
rcsDocControl![Revision] = Forms![frmAddNewDoc]![txtRevision]
rcsDocControl![Date_Added_DB] = Forms![frmAddNewDoc]![txtDate_Added_DB]
rcsDocControl![Type] = Forms![frmAddNewDoc]![cboType]
rcsDocControl![Owner] = Forms![frmAddNewDoc]![cboOwner]
rcsDocControl![Location] = Forms![frmAddNewDoc]![URL_Location]
rcsDocControl.Update
MsgBox "The Document has been Added!", vbDefaultButton1, "Document Added!"
txtDoc_ID = ""
txtTitle = ""
txtRevision = ""
txtDate_Added_DB = ""
cboType = ""
cboOwner = ""
URL_Location = ""
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