I am receiving a compile error: User-defined type not defined. Below is the code that I am using. I inherited this form and it was in an earlier version of Access. I highlighted the current errors! Could you look at the code and give me some direction.
I see that I should use code tags [ ]? Please let me know if I did this incorrect??
Thank you in advance.
[Private Sub Command12_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstcontact As ADODB.Recordset
Dim strCnn As String
Dim mydb As ADODB.Database
'Check that all fields are filled in
txtname.SetFocus
If txtname.Text = "" Then
err = err + 1
MsgBox "Please fill in the name box!" & err
End If
txtage.SetFocus
If txtage.Text = "" Then
err = err + 1
MsgBox "Please fill in the age box!"
End If
txtemail.SetFocus
If txtemail.Text = "" Then
err = err + 1
MsgBox "Please fill in the email box!"
End If
txtoccupation.SetFocus
If txtoccupation.Text = "" Then
err = err + 1
MsgBox "Please fill in occupation box!"
End If
lbaddress.SetFocus
If lbaddress.Text = "" Then
err = err + 1
MsgBox "Please fill in the address box!"
End If
'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\users\326lumm\google drive\access training\contacts.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn
' Open contact table.
Set rstcontact = New ADODB.Recordset
rstcontact.CursorType = adOpenKeyset
rstcontact.LockType = adLockOptimistic
rstcontact.Open "contact", cnn1, , , adCmdTable
'get the new record data
rstcontact.AddNew
rstcontact!name = txtname
rstcontact!email = txtemail
rstcontact!age = txtage
rstcontact!occupation = txtoccupation
rstcontact!address = lbaddress
rstcontact.Update
' Show the newly added data.
MsgBox "New contact: " & rstcontact!name & " has been successfully added"
'close connections
rstcontact.Close
cnn1.Close
Else
MsgBox "An Error has occurred, please check and try again"
End If
End Sub]