Open form & subforms at last viewed record

sonny123

Registered User.
Local time
Today, 11:26
Joined
Apr 8, 2011
Messages
31
I have a parent form with a sub form
so to refresh the form I am doing this

Code:
Private Sub Case_But_Click()

DoCmd.Close acForm, "Caseworker", acSaveNo
' do stuff here updating record set
DoCmd.OpenForm "Caseworker", acNormal

End Sub

fine so far except that when caseworker reopens i get the first form(or the last if i choose)
But i want reopen the record i just closed

i found this & followed it
http://www.access-programmers.co.uk/forums/showthread.php?t=150210&referrerid=90628

and here is what I have

Code:
Private Sub Form_Unload(Cancel As Integer)
LastRecordUsed = Me.ID
Debug.Print " Unload " & Me.ID
End Sub

and

Code:
Private Sub Form_Open(Cancel As Integer)
Debug.Print "open " & intLastRecordUsed
If intLastRecordUsed = 0 Then
   DoCmd.Maximize
Else
   Me.Filter = "[ID]=" & LastRecordUsed
   Me.FilterOn = True
   DoCmd.Maximize
End If

End Sub


the problem is that i reopen the form i just closed but i can no longer navigate to the other parent form records, presumably because the filter is ON.

i tried setting filter to False but that didnt work (obviously i suppose :rolleyes: but you never know till you try!)

so how do i get round this
reopen the form i just closed without setting the filter to true



EDIT:
ooh yes that registry trick in the refered to thread looks clever
any pointers / links on how i would do that ????
 
Oh, and for the registry bit look at SaveSetting and GetSetting.
 
I sort of get the idea (i think)
do it all in the click event i think is what your saying
(clean out the unload and open events)

heres what ive coded to my click event
but its still going to the first "caseworker" record:(

Code:
Private Sub Case_Ref_No_Label_Click()
intLastRecordUsed = Me.ID
DoCmd.Close acForm, "Caseworker", acSaveNo
'do stuff here updating record set
DoCmd.OpenForm "Caseworker"

Dim rs As Object
Set rs = Forms!Caseworker.RecordsetClone
rs.FindFirst "ID = " & intLastRecordUsed
Forms!Caseworker.rs.intLastRecordUsed
Set rs = Nothing

End Sub

it does run but it stll opens the first record not the one i closed
 
Double check this line compared to my example:

Forms!Caseworker.rs.intLastRecordUsed
Forms!frmEmployeesDetail.Bookmark = rs.Bookmark

I'd actually expect yours to error.
 
Yay!!

I think that the var lngBookmark being kinda similar to the word bookmark kind of threw me off course (not to mention a few beers that had been sunk last night :))

okay now i have it working

Code:
Dim rs As Object
Set rs = Forms!Caseworker.RecordsetClone
rs.FindFirst "ID = " & intLastRecordUsed
[B]Forms!Caseworker.Bookmark = rs.Bookmark[/B]
Set rs = Nothing

thanks Paul

now to check out that registry
 
Happy to help.

Beer + Access = :confused:
 

Users who are viewing this thread

Back
Top Bottom