Solved

Bookmark Help

Posted on 2013-11-14
3
222 Views
Last Modified: 2013-11-15
I have a command button that sets a value to "TRUE" and which works fine with the exception that the form returns to the first record. How can I get the form to stay on the same record once the UPDATE SQL runs?

Thanks for your help.

If MsgBox("Are you sure you want to assign " & Me.lstCName & " as chair of the " & [lstComName] & " committee?", vbYesNo + vbQuestion, strAppName) = vbYes Then
        
        DoCmd.RunSQL "UPDATE tblCommitteeDetail SET tblCommitteeDetail.Chair = True WHERE [CommitteeID] = " & Me.CommitteeID.Value
        fDisplayPopup "Success", [lstCName] & " has been added as  chair of the " & [lstComName] & " committee.", 2
      
End If
End Sub
       

Open in new window

0
Comment
Question by:hbatt
  • 2
3 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39649992
Try this:

dim lngID as long
If MsgBox("Are you sure you want to assign " & Me.lstCName & " as chair of the " & [lstComName] & " committee?", vbYesNo + vbQuestion, strAppName) = vbYes Then
         lngID = Me.ID '*** Change this to the actual name of your PK or autonumber field
        DoCmd.RunSQL "UPDATE tblCommitteeDetail SET tblCommitteeDetail.Chair = True WHERE [CommitteeID] = " & Me.CommitteeID.Value
        fDisplayPopup "Success", [lstCName] & " has been added as  chair of the " & [lstComName] & " committee.", 2
       Me.RecordsetClone.FindFirst  "ID = " & lngID
       Me.Bookmark = Me.RecorsetClone.Bookmark
      
End If
End Sub

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39649999
This is a little cleaner, and handles no-match conditions:


dim lngID as long
dim rs as dao.recordset

If MsgBox("Are you sure you want to assign " & Me.lstCName & " as chair of the " & [lstComName] & " committee?", vbYesNo + vbQuestion, strAppName) = vbYes Then
         lngID = Me.ID '*** Change this to the actual name of your PK or autonumber field
        DoCmd.RunSQL "UPDATE tblCommitteeDetail SET tblCommitteeDetail.Chair = True WHERE [CommitteeID] = " & Me.CommitteeID.Value
        fDisplayPopup "Success", [lstCName] & " has been added as  chair of the " & [lstComName] & " committee.", 2

       set rs = Me.RecordsetClone
       rs.FindFirst  "ID = " & lngID
       if rs.NoMatch = False then Me.Bookmark =rs.Bookmark
       set rs = nothing
      
End If
End Sub

Open in new window

0
 

Author Closing Comment

by:hbatt
ID: 39651572
Thanks for your quick answer and I apologize for my slow response. I was finessing the code a bit so it would also remove someone as chair based on the caption of the command button.

This works perfectly!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will show you how to use shortcut menus in the Access run-time environment.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question