OpenArgs to open form (1 Viewer)

OnlyTD

Registered User.
Local time
Yesterday, 21:27
Joined
Jul 26, 2018
Messages
42
HI I have a form with a button that when clicked I want it to create a new record in the first table then open the next form and create a corresponding record in the related table.
I used the following which worked at first but now it doesnt:

Private Sub Command62_Click()

DoCmd.GoToRecord , , acNewRec
Me.BI_Date_Requested.Value = Now()
Me.BI_Status.Value = "Generated"
Refresh

If Me.Dirty = True Then Me.Dirty = False

DoCmd.OpenForm "FrmRoom_Hire_info_BIO_subform2_V2", WhereCondition:="[BI_ID_ptr]=" & Me![BI_ID], Windowmode:=acDialog, OpenArgs:=Me.BI_ID


In the second form I have the following in the ON OPEN command:

Private Sub Form_Open(Cancel As Integer)

If Me.OpenArgs <> "" Then
Me![BI_ID_ptr].DefaultValue = "" & Me.OpenArgs & ""
End If

End Sub


The line below works if there is already a corresponding record in the second table but I cannot figure out how to create a new record in the second form.


DoCmd.OpenForm "FrmRoom_Hire_info_BIO_subform2_V2", WhereCondition:="[BI_ID_ptr]=" & Me![BI_ID], Windowmode:=acDialog, OpenArgs:=Me.BI_ID


Please could someone help me with this?
 

NauticalGent

CopyPaster of the First Order
Local time
Today, 00:27
Joined
Apr 27, 2015
Messages
5,183
Try
Code:
Private Sub Form_Open(Cancel As Integer)

If Me.OpenArgs <> "" Then
    Me![BI_ID_ptr].DefaultValue = "" & Me.OpenArgs & ""
Else
    Me.NewRecord = True
End If

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:27
Joined
May 7, 2009
Messages
16,874
you may try moving your code from Open event to Load event of the Form.
on Open event, No controls, exist yet or not yet Initialized.
 

OnlyTD

Registered User.
Local time
Yesterday, 21:27
Joined
Jul 26, 2018
Messages
42
HI thank you so much for your reply, I used the code you gave me but it stops on ' Me.NewRecord = True' with the error message cant assign to a read only?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:27
Joined
May 7, 2009
Messages
16,874
Code:
Private Sub Form_Load(Cancel As Integer)
If Me.OpenArgs <> "" Then
    Me![BI_ID_ptr].DefaultValue = "" & Me.OpenArgs & ""
Else
    Docmd.GotoRecord,,acNewRec
End If

End Sub
 

Users who are viewing this thread

Top Bottom