Cannot use browseto or search in the onload event (1 Viewer)

nitwitnit

New member
Local time
Today, 10:58
Joined
Jun 23, 2016
Messages
2
What I'm trying to do is this - I have a navigation form with multiple subforms. Each subform accesses different tables. I would like subform A if it is on record 10, say I switch to subform B, when I switch back to subform A I want it to automatically load record 10 (the last previous record).

The problem is all of the events in Access 2013 appear to fire BEFORE the form loads. So if I try to use browseto or searchforrecord it doesn't work. The current code in the subform that I want to load the previous record is:

Code:
Private Sub Form_Load()
PubOperationLoad = True
MsgBox "Load"
MsgBox PubCurrentOperation
If Not (IsEmpty(PubCurrentOperation) Or IsNull(PubCurrentOperation) Or PubCurrentOperation < 2) Then
    DoCmd.SearchForRecord acForm, "Final UI Operation", , "ID=" & PubCurrentOperation
End If
End Sub
where PubOperationOperation is a public variable that updates on oncurrent. PubOperationLoad just keeps track if oncurrent is firing because the form was loaded (in this case do not save the new record), or because the record was changed (in that case save the new record) Oncurrent reads:
Code:
Private Sub Form_Current()
MsgBox "current"
If Not PubOperationLoad Then
    PubCurrentOperation = Forms![Final UI Main Form]!NavigationSubform.Form.CurrentRecord
Else
    PubOperationLoad = False

End If
End Sub
 

GohDiamond

"Access- Imagineer that!"
Local time
Today, 09:58
Joined
Nov 1, 2006
Messages
550
If the form is actually NOT LOADED you can't focus on it nor on it's associated controls. LOAD/OPEN the form (A) from (B), setfocus on the Form (A) and on the control (in A) and execute searchforrecord from (B) then close your current form (B), leaving the recently Loaded form(A) in view.

Does that help?
Cheers,
Goh
 

nitwitnit

New member
Local time
Today, 10:58
Joined
Jun 23, 2016
Messages
2
Building my own navigation form and subform may be the easiest solution (or most elegant). I also thought of having the event fire when the button that is pushed to change forms loses focus, this causes a slight delay when the form is swapped but would do what I want. However, I'm having problems navigating to the new record even with a button with the formula:

Code:
DoCmd.SearchForRecord acForm, "Final UI Operation", , "ID=" & PubCurrentOperation

I also tried (and this gives you an idea of the structure of the UI):

Code:
DoCmd.SearchForRecord acForm, [Final UI Main Form]!NavigationSubform.Form.SourceRecord, , "ID=" & PubCurrentOperation

Both give the same error - "Microsoft Access can't find the field '|1|' referred to in your expression. The Operation table is the underlying table to the form and does indeed have an ID field - as do all the other tables (I named all the tables ID #'s - ID)
 

Users who are viewing this thread

Top Bottom