Solved

Bookmark Help

Posted on 2013-11-14
3
212 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

My experience with Windows 10 over a one year period and suggestions for smooth operation
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now