Results 1 to 8 of 8
  1. #1
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32

    Going to first record after loading the tablw

    I am populating an empty tabl with import from excel. No problem. I have a while loop following in the same procedure that goes hrough all the records and does some cleanup work. No Problem. However after the table is loaded my current record is at the last Record. My while loop wants to start at the first record an do its job until the end . I have not found a way to get the code go to the first record. I have tried several suggestions from other sites and the gotorecord does not get done either. I'm sure there is a way but I have not found it. Any Ideas?



    Thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,024
    Show your code?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32
    'Prepare TblGuest and Guest for new imported data
    DoCmd.SetWarnings False
    DoCmd.DeleteObject acTable, "Guest"
    DoCmd.RunSavedImportExport "Import-Guests"
    DoCmd.OpenQuery "QdelTblGuest"
    DoCmd.OpenQuery "QappGuestToTblGuest"
    DoCmd.SetWarnings True
    MsgBox "Guest profiles have been imported"

    'FixPhone Numbers
    Dim Area As String
    Dim Exch As String
    Dim Number As String

    MsgBox Me.CurrentRecord 'This shows 17 which is the number of records in the table
    While Me.CurrentRecord <= Me.Recordset.RecordCount
    Do My stuf

    Wend
    End Sub


    The while loop needs to start at the beginning of the table

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,024
    Ok, you say the GotToRecord does not get 'done'

    Have you walked through the code with F8 ?

    Have you tried
    docmd.RunCommand acCmdRecordsGoToFirst
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32
    I had not tried that particular line of code and it works by giving me a 1 in the msgbox. The first line of code after the while, If Len(Phone.Value & "") = 0 Then Errors with the message 'Record is deleted"

  6. #6
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32
    This makes me think that I am looking at the 18th record which obviously is blank

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,123
    Probably the easiest would be to add a Me.Requery just before your loop (where the msgbox call is now) but instead of navigating through the form you should use a recordset:
    Code:
    Dim rst as DAO.Recordset
    
    
    Set rst= Me.recordsetclone
    
    
    if rst.recordcount=0 then Exit Sub 
    
    
    rst.MoveFirst
    Do until rst.EOF
    
    
      'Do your stuff here
       rst.Edit
       rst("Phone")= WhateverChangeYouWantToMake
       rst.Update
    
    
    
    
    rst.MoveNext
    Loop
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,024
    Other option would be
    DoCmd.GoToRecord acDataForm, Me.Name, acFirst

    However F8 and inspecting the fields/variables would be my choice

    For now just Debug.print the ID of each record to see what is happening. Then when you get that working, add the fancy stuff in.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Loading A Form
    By Robert2150 in forum Access
    Replies: 5
    Last Post: 06-24-2015, 01:38 PM
  2. Replies: 34
    Last Post: 07-03-2014, 12:20 PM
  3. Event trigger at loading each record
    By xcheshirecat in forum Forms
    Replies: 5
    Last Post: 06-12-2014, 10:11 AM
  4. Loading and using DLL
    By mujaqo in forum Programming
    Replies: 1
    Last Post: 09-02-2013, 10:40 AM
  5. Loading the form with selected record
    By emilylu3 in forum Access
    Replies: 1
    Last Post: 12-09-2005, 07:49 AM

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