Results 1 to 9 of 9

Thread: PLEASE DEBUG!!!

  1. #1
    gdboling
    Guest

    PLEASE DEBUG!!!

    I am having a problem with some NotInList Code. Can someone debug this for me plase. I am not prompting whether or not the user wants to add the data. It will just add it.
    Private Sub FigureName_NotInList(NewData As String, Response As Integer)

    Dim Db As database - I am getting a user type
    not defined error on this line
    Dim Rs As Recordset
    Dim Msg As String
    Dim CR As String

    CR = Chr$(13)

    ' Exit this subroutine if the combo box was cleared.
    If NewData = "" Then Exit Sub

    ' If the user chose to add a new customer, open a recordset
    ' using the Customers table.
    Set Db = CurrentDb
    Set Rs = Db.OpenRecordset("Lookup", DB_OPEN_TABLE)
    ' Let code execution continue if a run-time error occurs.
    On Error Resume Next
    ' Create a new record.
    Rs.AddNew

    ' Assign the NewData argument to the CompanyName field.
    Rs![FigureName] = NewData
    ' Save the record.
    Rs.Update

    End Sub

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PLEASE DEBUG!!!

    On first glance, a few things:

    1) You're getting the "User Type not defined" error because of a missing reference. Go to Tools|References... and make sure DAO is checked (3.5 or 3.6 depending on what version of Access you're using)

    2) There's no EndIf at the end to conclude your "If NewData" statement.

    3) You used DB_OPEN_TABLE as the argument for the OpenRecordset command. That's a legacy argument carried over from older versions of Access. You should use "dbOpenTable" (for 97 or 2000).

    4) You'll want to use RS.Close, Set RS = Nothing and Set DB = Nothing after you're done with the updates.

    5) Even though you may have used the Msg and CR variables earlier, they're not being used in the Sub you've posted here. If they're not being used, then remove them.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  3. #3
    gdboling
    Guest

    Re: PLEASE DEBUG!!!

    THANK YOU SOOOOOOOOO MUCH

  4. #4
    gdboling
    Guest

    Re: PLEASE DEBUG!!!

    Now I am getting a type mismatch on this line. What the heck??

    Set Rs = Db.OpenRecordset("Lookup", DbOpenTable)

  5. #5
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PLEASE DEBUG!!!

    Hmm...double check the reference to make sure it's DAO - not ADO. Also, you might try dbOpenDynaset instead of dbOpenTable.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  6. #6
    gdboling
    Guest

    Re: PLEASE DEBUG!!!

    I check the reference, it is Microsoft DAO Object and I changed it to Dynaset and I still get the same error. Here is my code again.

    Private Sub FigureName_NotInList(NewData As String, Response As Integer)

    Dim Db As database
    Dim Rs As Recordset


    ' Exit this subroutine if the combo box was cleared.
    If NewData = "" Then Exit Sub

    ' If the user chose to add a new customer, open a recordset
    ' using the Customers table.
    Set Db = CurrentDb
    Set Rs = Db.OpenRecordset("Lookup", dbOpenDynaset)
    ' Let code execution continue if a run-time error occurs.
    On Error Resume Next
    ' Create a new record.
    Rs.AddNew

    ' Assign the NewData argument to the CompanyName field.
    Rs![FigureName] = NewData
    ' Save the record.
    Rs.Update
    Rs.Close

    End Sub

    I didn't know where to put the Rs = nothing.
    Sorry if I sound like an idiot, I am trying to learn this as I go.

    <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Tennessee
    Posts
    194
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PLEASE DEBUG!!!

    Would it help to add the dao
    Dim Db As DAO.database
    Dim Rs As DAO.Recordset

  8. #8
    gdboling
    Guest

    Re: PLEASE DEBUG!!!

    YES THAT WORKED!!!!! Hurray!!

    Ok, now another question:

    It ads it to my lookup table but not to the entry table. And I still get an error, that the name is not in the lookup list at then end of the add routine.

    Any ideas?

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PLEASE DEBUG!!!

    Try refreshing (Me!<Lookup>.REQUERY) the lookup control.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •