Results 1 to 5 of 5
  1. #1
    adams77 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    16

    mydb - User-defined type not defined

    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]

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    1.You are re-inventing the wheel. There is NO need to use ADO code.
    All the data is in your database, so dont build a new one.
    mydb = currentdb

    2. there is no need to use code.
    This is what forms and queries do. Add new records/edit records/etc.

  3. #3
    adams77 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    16
    are you telling me to not use VBA code and just do it from the form or queries?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    yes. Easier. code free.

  5. #5
    adams77 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    16
    Thank you for yo0r help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 11-12-2013, 04:13 PM
  2. user-defined type not defined
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 05-09-2013, 05:15 PM
  3. Replies: 1
    Last Post: 12-14-2012, 12:32 AM
  4. Replies: 4
    Last Post: 06-08-2012, 09:08 AM
  5. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums