Results 1 to 3 of 3
  1. #1
    Tuckejam is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jan 2020
    Posts
    168

    Lost in a Maze of Me.OpenArgs

    First let me state that I have been at this since around 3 this morning, and at one point I'm pretty sure I knew What I was doing, but now I'm just lost, wondering around and randomly pasting "Me.OpenArgs" in random places.

    In Short, imaging you have a form and you are clicking next going through the records one by one, and then you click the "Add New" button and it takes you to a new form to add a new record.

    But you didn't mean to or you forgot what you were doing so you click on the cancel button. I want it to close the "add new" screen and go back to the record I was on. and right now everything I try always goes back the first record

    Please dont laugh to hard at the code below, I'm Tired and I dont know what I am doing.
    I have a few lines of code that have been turned off using the 'comment marker
    this is because I was trying different things and trying to reason through what was working and what wasn't


    On the form that closes when I click cancel

    Private Sub Cancel_Click()
    Dim HouseID As Long


    If MsgBox(" Are you sure you want to cancel? " & vbCrLf & " Information Will not be Saved", vbYesNo) = vbYes Then
    'Me.AllowDeletions = True
    'DoCmd.RunCommand acCmdDeleteRecord
    'Me.AllowDeletions = False
    'HouseID = 0
    'HouseID = Me!HouseID
    Me.Undo 'Undo any changes and go Back to Houses Form
    DoCmd.Close acForm, "frm_HouseAddEditDel"
    DoCmd.OpenForm "Frm_Houses", OpenArgs:=HouseID
    End If
    'Stay on form
    End Sub


    On the Form that Opens back up (and goes to the first record, not the record I was on originally)

    Private Sub Form_Open(Cancel As Integer)
    Me.AllowAdditions = False
    Me.AllowEdits = False
    Me.AllowDeletions = False

    If Nz(Me.OpenArgs) <> 0 Then
    Me!HouseID.SetFocus
    DoCmd.FindRecord Me.OpenArgs

    End If

    End Sub


    Even though I haven't figured this out, I am starting feel better about it VBA, still feel like I'm wandering around and lost, but I don't feel blindfolded anymore.
    So I really do appreciate the help

  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,521
    Rather than OpenArgs you could use this:

    http://www.baldyweb.com/Bookmark.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you try this:
    Code:
    'frm_HouseAddEditDel
    Private Sub Cancel_Click()
    Dim HouseID As Long
    If MsgBox(" Are you sure you want to cancel? " & vbCrLf & " Information Will not be Saved", vbYesNo) = vbYes Then
       
    Me.Undo 'Undo any changes and go Back to Houses Form
       
    'your code         
       DoCmd.OpenForm "Frm_Houses",,,,, Me.HouseID
       
        ''Paul's code
        'Dim rs As Object
        'Dim lngBookmark As Long
        ''set a variable to the current record
        'lngBookmark = Me.HouseID
        ''open the new form
        'DoCmd.OpenForm "Frm_Houses"
        ''take it to the selected record
        'Set rs = Forms!Frm_Houses.RecordsetClone
        'rs.FindFirst "HouseID = " & lngBookmark          
          'Forms!frmEmployeesDetail.Bookmark = rs.Bookmark
        'Set rs = Nothing
    
    
       DoCmd.Close acForm, me.Name
    End If
    'Stay on form
    End Sub
    
    
    'Frm_Houses
    Private Sub Form_Open(Cancel As Integer)
    Me.AllowAdditions = False
    Me.AllowEdits = False
    Me.AllowDeletions = False
    
    
    'your code can be commented out when trying Paul's
    If Nz(Me.OpenArgs) <> 0 Then
       Me.HouseID.SetFocus
       DoCmd.FindRecord Me.OpenArgs
    'your code can be commented out when trying Paul's
    End If
    
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. OpenArgs and FindRecord combination
    By Stretholox in forum Access
    Replies: 7
    Last Post: 12-10-2014, 10:35 AM
  2. Replies: 5
    Last Post: 01-27-2013, 06:04 PM
  3. How to set openargs of sub report?
    By flippedbeyond in forum Programming
    Replies: 11
    Last Post: 09-20-2011, 08:24 PM
  4. Open a second form using the OpenArgs
    By blueraincoat in forum Forms
    Replies: 6
    Last Post: 06-02-2011, 06:19 AM
  5. Showing OpenArgs in a Report.
    By SIGMA248 in forum Programming
    Replies: 2
    Last Post: 04-01-2011, 11:57 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