Results 1 to 9 of 9
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    VBA Code Help Please

    I get this error on my form:

    The following runtime error occured:
    Number: 3265
    Description: Item not found in this collection
    Object Type: Form
    Procedure: No_LostFocus
    Object: frmMain

    I changed this code: (which works perfectly)
    Code:
    Private Sub No_LostFocus()
    Dim t_cbo_name
    Dim strsql AS String
    Dim db AS database
    Dim rec AS Recordset
    Set db = currentDB
    Set rec = db.OpenRecordset("tbl_initial_seeder")
    
    Do until rec.EOF
    with rec
       If Trim(!login_id) = Trim(Me.txt_winusername) Then
       t_name = ![id]
       t_cbo_name = !p
          If IsNull(Me.Data_Input_by_name_box) Then
          Me.Data_Input_by_name_box = t_cbo_name
          Else
          End If
    
    Else
    
    End If
    .MoveNext
    
    End With
    Loop
    
    Set rec = Nothing
    Me.WinUserName_box = txt_winusername
    Me.date_updated = Now()
    Debug.Print t_name, Me.txt_winusername, t_cbo_name
    
    Do.Cmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    Exit_no_LostFocus()
    
    Exit Sub
    To this code which is what produces the error I posted above
    Code:
    Private Sub No_LostFocus()
    Dim t_cbo_name
    Dim strsql AS String
    Dim db AS database
    Dim rec AS Recordset
    Set db = currentDB
    Set rec = db.OpenRecordset("tbl_j")
    
    Do until rec.EOF
    with rec
       If Trim(!login_id) = Trim(Me.txt_winusername) Then
       t_name = ![id]
       t_cbo_name = !Name
          If IsNull(Me.Record_Input_By) Then
          Me.Data_Input_by_name_box = t_cbo_name
          Else
          End If
    
    Else
    
    End If
    .MoveNext
    
    End With
    Loop
    
    Set rec = Nothing
    Me.WinUserName_box = txt_winusername
    Me.date_updated = Now()
    Debug.Print t_name, Me.txt_winusername, t_cbo_name
    
    Do.Cmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    Exit_no_LostFocus()
    
    Exit Sub



    I am wanting to change the db.OpenRecordset to another table (table_j)
    The t_name = ![id] ---- I am assuming this is fine, since both tables have "id"
    the t_cbo_name = !p --- I am trying to change that to name, because I want it to display the name in the table I am trying to change over to

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Looking things over rather quickly, be sure you have not used a Reserved word as the name of *any* object: table, field, control, form, etc. Here's a good reference with which to check: http://www.allenbrowne.com/AppIssueBadWord.html
    There are ways around it but it is far better to simply change the name used. Access gets confused and cannot determine to what you are referring.

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Ah, that is a long list, I didn't know about it, thanks for the valuable link! I see that the word "Name" is on the list, and I am trying to use that word. Will I need to change it on my table as well, since that is what I am referencing in the VB Code?

  4. #4
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I changed the word "Name" as it was on the list, but that is the only word that jumped out at me from the list, but I still receive the same error?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Some basic rules of thumb to follow:
    1) Always put Option Explicit at the top of your class module to force defining variables before using them.
    2) The DoMenuItem syntax is basically obsolete these days. Change to the DoCommand systax. Here's a link for translation: http://www.accessruncommand.com/domenuitem.htm
    3) Disambiguate your variables. Instead of
    Dim db As Database
    ...it should be...
    Dim db As DAO.Database
    Dim rec As DAO.Recordset
    4) If you Set something in your procedure then Set it to Nothing before leaving the procedure. That means *every* object you Set.
    5) You should also .Close a Recordset before Setting it to Nothing.
    Does the debugger highlight the line is does not like?

  6. #6
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    The Debugger does not display any issues, the error pops up when I reach that point on the form. I will try the other suggestions that you offered, and post back when I have exhausted those options.

  7. #7
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I followed:
    4) If you Set something in your procedure then Set it to Nothing before leaving the procedure. That means *every* object you Set.

    And that corrected the Error on the form, I was getting! Thanks for your help.

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by jo15765 View Post
    I followed:
    4) If you Set something in your procedure then Set it to Nothing before leaving the procedure. That means *every* object you Set.

    And that corrected the Error on the form, I was getting! Thanks for your help.
    Very nice. I was just looking at your code in split screen and comparing it. Outcomes like this are so interesting, yet overlooked all the time. I'm at this stage right now in javascript.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Thanks for posting back with your success.

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

Similar Threads

  1. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  2. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  3. how to get to the raw code
    By YankeeImperialistDog in forum Programming
    Replies: 1
    Last Post: 03-05-2010, 01:55 PM
  4. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  5. Need help with code
    By hoenheim in forum Programming
    Replies: 9
    Last Post: 09-11-2008, 04:19 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