OpenArgs to open form

OnlyTD

Registered User.
Local time
Yesterday, 16:41
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?
 
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
 
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.
 
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?
 
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

Back
Top Bottom