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

    Open form to a specific record problem

    I am using the code below to open a form to a specific record based on record count. The problem is that the message box shows the proper record count, but it always opens the first record.
    Any thoughts

    Private Sub BtnDaily_Click()
    Dim RecCnt As Integer
    Dim FileEnd As Integer
    FileEnd = DCount("RecordDate", "TblSummary")



    RecCnt = 1
    'Determine if todays record has started


    DoCmd.GoToRecord , , acFirst
    Do While RecCnt < FileEnd + 1
    If RecordDate = Date + NewDay Then
    GoTo Found
    End If
    RecCnt = RecCnt + 1
    DoCmd.GoToRecord , , acNext
    Loop

    DoCmd.OpenForm "FrmDailyAdd", acNormal, , , , , RecCnt
    LDate = RecordDate
    Exit Sub

    The above code works great.


    Found:
    MsgBox RecCnt
    DoCmd.OpenForm "FrmDailyUpdate", acNormal, , , , , RecCnt

    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    What do you expect the RecCnt variable to do in the OpenForm code? If my count is correct, you have it in the OpenArgs position, which won't do anything on its own. You'd need code in the form to put that value to any use. Is this appropriate?

    http://www.baldyweb.com/wherecondition.htm

    tweaked to open the form to a specific date.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32
    Thanks Taking you advise I have changed the code as follows. I still get a new record regardless of how I change the where clause. ID is the table primary key. I search for the dated record that I want and put that into the recCnt then attempt to open the record with the desired date.

    Private Sub BtnDaily_Click()
    Dim RecCnt As Integer
    Dim FileEnd As Integer
    FileEnd = DCount("RecordDate", "TblSummary")



    RecCnt = 1
    'Determine if todays record has started
    DoCmd.GoToRecord , , acFirst
    Do While RecCnt < FileEnd + 1
    If RecordDate = Date + NewDay Then
    GoTo Found
    End If
    RecCnt = RecCnt + 1
    DoCmd.GoToRecord , , acNext
    Loop

    DoCmd.OpenForm "FrmDailyAdd", acNormal, , RecCnt
    LDate = RecordDate
    Exit Sub


    Found:
    RecCnt = ID

    MsgBox RecordDate
    MsgBox RecCnt
    DoCmd.OpenForm "FrmDailyUpdate", acNormal, , "[ID] =" & Me.RecordDate
    End Sub

    Both RecordDate and RecCnt are correct for the desired record

    Frustrated Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    This:

    DoCmd.OpenForm "FrmDailyAdd", acNormal, , RecCnt

    is using a count so will resolve to:

    DoCmd.OpenForm "FrmDailyAdd", acNormal, , 7

    which is not a valid wherecondition. This

    DoCmd.OpenForm "FrmDailyUpdate", acNormal, , "[ID] =" & Me.RecordDate

    appears to be comparing an ID field to a date field, which presumably will never result in a valid record.

    Can you attach the db here to play with?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    SeniorCitizen is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    32
    Thanks for smack about the head. Your comment that I cant compare a record number to a date did it. I fix that and all is well.

    DoCmd.OpenForm "FrmDailyUpdate", acNormal, , "[ID] =" & Me.ID

    I appreciate the help

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 01-30-2022, 01:34 AM
  2. Open form with specific record
    By Lukael in forum Programming
    Replies: 14
    Last Post: 11-16-2015, 06:31 AM
  3. Open form to specific record
    By zoro.1983 in forum Access
    Replies: 3
    Last Post: 05-31-2015, 11:04 AM
  4. Open form on specific record
    By iky123 in forum Forms
    Replies: 1
    Last Post: 04-11-2012, 09:56 AM
  5. Open Form to Specific Record
    By batowl in forum Forms
    Replies: 1
    Last Post: 04-08-2011, 10:10 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