Close Form1 open Form2 retain record (1 Viewer)

matt beamish

Registered User.
Local time
Today, 00:11
Joined
Sep 21, 2000
Messages
208
I need to move between forms and get some conditional formatting to update whilst this is happening. Ive tried all sorts of requery combinations but cant get it to work, and I think I need to close one form before opening the next, and vice versa on the way back to the original form.
If Form 1 is called "F_Project_Summary_Index" and my Form 2 is "F_Project_Summary" and my control on both forms is "Job_No" what would the VBA be to close Form 1 and open Form 2 on the same "Job_No".
Thanks in advance
Matt
 

jfgambit

Kinetic Card Dealer
Local time
Today, 00:11
Joined
Jul 18, 2002
Messages
798
Not sure why you need to close the first form, but here is the code to open the second form to your record:

Dim stDocName As String
Dim stLinkCriteria As Variant

stDocName = "F_Project_Summary"
stLinkCriteria = Forms!F_Project_Summary_Index!Job_No
DoCmd.OpenForm stDocName, , , stLinkCriteria
 

Simon_MT

Registered User.
Local time
Today, 00:11
Joined
Feb 26, 2007
Messages
2,177
The trick here is to Open Form2 before you close Form1. When you open Form2 use a filter of Job_No.

Code:
Function Artists_Details()

Dim MyObjectName As String
          MyObjectName = CodeContextObject.Name
    
    DoCmd.OpenForm "Artists Details", acNormal, "", ArtistsFilter, , acWindowNormal
    DoCmd.Close acForm, MyObjectName
    
End Function

Simon
 

matt beamish

Registered User.
Local time
Today, 00:11
Joined
Sep 21, 2000
Messages
208
Thanks for these, Ill try when back at my desk tomorrow...
The reason for wanting to close the forms is that I want some values that affect formatting and display to be requeried on the first form that have been changed when the second form was open. As I have been having trouble getting a requery to work with the forms staying open, but I know that closing the forms and opening has the desired effect, I reckon that doing just that programmatically was the next thing to try.
thanks again
 

ghudson

Registered User.
Local time
Yesterday, 19:11
Joined
Jun 8, 2002
Messages
6,195
Me.Requery will 'requery' the open form.
DoCmd.Close Me.Name will 'close' the open form.
 

ghudson

Registered User.
Local time
Yesterday, 19:11
Joined
Jun 8, 2002
Messages
6,195
What does ".Name" mean to Access in this context?
thanks

Refers to the Name of the current form that the code is run from.

Try MsgBox Me.Name and if will display the name of the form that you run that code in.
 

Users who are viewing this thread

Top Bottom