Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bookmark, Recordset.move hiding records

Status
Not open for further replies.

cbirknh

Programmer
Jun 28, 2002
14
US
Hi,
I have form listing all appointments on a specified date (or set of dates) and a "cmdOpen" button which opens the appointment details form and closes the appt list form. I would like to set it up so when the user reopens the appt list form, the focus is returned to the same spot on the appointment list form. I have tried two methods:
1) Set a bookmark and try to return to the bookmark. The code looks to see if a bookmark exists and goes to that record if so:
If Nz(gblBookmark, 0) <> 0 Then
rst.Bookmark = gblBookmark
End If

2) Look for the appointment ID (BIC):
If gblBIC <> &quot;&quot; Then
rst.MoveFirst
Do Until rst!BIC = gblBIC
rst.MoveNext
Loop
End If

Both of these procedures find the appropriate record (unless the ordering has changed- then the bookmark method may off a record or two), but unfortunately, the other records are hidden. I still what to display all the records, I just want the focus on the correct record. How can I accomplish this?

Thank you very much,
Chris
 
Rather than closing the list form, you can just hide it, and it won't move off the appropriate record.

Forms!MyFormName.Visible = False

where you currently close the form, and show it again when you fire the close-detail code.
 
Having a 'central' form that could be opened from several other forms and has to be reopened at the same point, I used the following method to do this:
First form passes its name and record ID when opening the second form:

DoCmd.OpenForm &quot;form2&quot;, , , , , , Me.Name & &quot;:&quot; & Me(&quot;NameOfControlBoundToPrimaryKey&quot;)

You can now close the first form. Its name and 'bookmark are stored in the OpenArgs property of the second form, separated by &quot;:&quot;.

When done with the second form, I use the Close event to return from where I came:

Sub Form_Close()
Dim frmName$
Dim RecID
If OpenArgs<>&quot;&quot; Then
'Form has been opened from another form
'retrieve the name of the form
frmName = Left(OpenArgs, Instr(OpenArgs, &quot;:&quot;)-1)
'retrieve the record ID
RecID = Val(Trim(Right(OpenArgs, Len(OpenArgs)-Instr(OpenArgs,&quot;:&quot;)))

'Open the form
DoCmd.OpenForm frmName
With Forms(frmName).RecordsetClone
'search for the record
.FindFirst &quot;PrimaryKeyName = &quot; & RecID
If Not .NoMatch Then Forms(frmName).Bookmark = .Bookmark
End With
Else
'OpenArgs property does not store anything
End If
End Sub

Just hope I didn't make too many typing mistakes...
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Thanks for the replies. Downwitchyobadself, I would like to close and reopen the form because information is likely to change or records deleted by the time the user returns to the form. Daniel, the open args sounds like a great idea. I have been accomplishing this by storing the form name and primary key information as global variables. I will probably need to continue this because the user can go to other forms before returning to this one.
My problem (or lack of understanding) is really with the .find and .bookmark stuff. I can get the form to return to the correct record (on its on open procedure), but it hides the other records that should be displayed in this continuous form. I have found, though, if after I return to the form, I open it in design view then return to form view, all records are displayed and the cursor is at the bookmarked record correctly. What is going on here?

Thanks again,
Chris
 
Are you using a bookmark directly on the form's recordset? If not, what is your code to synch your recordsets?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top