Switch to another Form at the same record by Macro

  • Thread starter Thread starter Tony WONG
  • Start date Start date
T

Tony WONG

there is a button to switch (openform) to another interface.

how can i stay at the same record after jump into another interface

in other words, record #53 is stayed at the main screen.

after jump into another sub-screen, how can instruct Access to jump to
record #53?

Thanks a lot.

Tony
 
Use the Where Condition of the OpenForm Action. Relational databases don't
have the concept of record #. You "find" a record by using its primary key.
 
Hi Tony

Here's a little code for you to use hope it is usefull let me know how you
get on

'To Open FORM2 from FORM1 (current form) where the field is TEXT format
DoCmd.OpenForm "FORM2", , , "[TEXTfield]='" & Forms!FORM1!
YourCurrentField & "'"

'To Open FORM2 from FORM1 (current form) where the field is NUMBER /
AUTONUMBER format
DoCmd.OpenForm "FORM2", , , "[NUMBERfield]=" & Forms!FORM1!
YourCurrentField

'If you want to do a check to make sure this has gone to the right record use
' the following. I have put a procedure that if it is the wrong record
' then it will close FORM2 and display a message box but I hope you get the
' idea of how it works

' After the 'Docmd.Openform....

If Forms!FORM2!TEXTfield = Forms!FORM1!YourCurrentField Then
Forms!FORM2.SetFocus
'or
Forms!FORM2!ANOTHERfield.SetFocus
Else
DoCmd.Close acForm, "FORM2"
MsgBox "The Record Couldn't Be Found", vbCritical, "Error Occured"
End If


Rich
 
Thanks a lot.

It works now.


Rich Wills via AccessMonster.com said:
Hi Tony

Here's a little code for you to use hope it is usefull let me know how you
get on

'To Open FORM2 from FORM1 (current form) where the field is TEXT format
DoCmd.OpenForm "FORM2", , , "[TEXTfield]='" & Forms!FORM1!
YourCurrentField & "'"

'To Open FORM2 from FORM1 (current form) where the field is NUMBER /
AUTONUMBER format
DoCmd.OpenForm "FORM2", , , "[NUMBERfield]=" & Forms!FORM1!
YourCurrentField

'If you want to do a check to make sure this has gone to the right record
use
' the following. I have put a procedure that if it is the wrong record
' then it will close FORM2 and display a message box but I hope you get
the
' idea of how it works

' After the 'Docmd.Openform....

If Forms!FORM2!TEXTfield = Forms!FORM1!YourCurrentField Then
Forms!FORM2.SetFocus
'or
Forms!FORM2!ANOTHERfield.SetFocus
Else
DoCmd.Close acForm, "FORM2"
MsgBox "The Record Couldn't Be Found", vbCritical, "Error Occured"
End If


Rich



Tony said:
there is a button to switch (openform) to another interface.

how can i stay at the same record after jump into another interface

in other words, record #53 is stayed at the main screen.

after jump into another sub-screen, how can instruct Access to jump to
record #53?

Thanks a lot.

Tony
 
Back
Top