Okay, bare with me, this is a really hard question to describe, and I'm fairly new to VBA.
I have a 'Customer Form' with a Command Button to create a New Order in an 'Order Form'. I can get the button to Open the 'Order Form' to a New Record, but I can't get it to pass the 'CustomerID' to the 'Order Form' Combo Box 'CustomerID'. I need the 'Order Form' to auto-populate with information from the 'Customer Form'.
Order Form:
The Customer Combo Box shows the Customer Full Name, but is bound to the CustomerID
Here's the VBA Code I have tried:
Private Sub BtnNewOrder_Click()
DoCmd.OpenForm FormName:="Order Form", View:=acNormal, OpenArgs:=Me.CustomerID.Value
DoCmd.GoToRecord , , acNewRec
End Sub
Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.CustomerID = Me.OpenArgs
End If
End Sub
I've been browsing the web for days without any luck. I'm sure this question has been asked before, but I haven't been able to find the right solution. Feel free to simply point me in the right direction.
You have to use the forms on-load event. The on open event is too soon.
On Open event - allows testing of controls and values - you can set cancel = true and form will not load. So, on open is for checking/testing if you want to let the form open, based on custom code that checks things. If you don't want the form to load - you can set Cancel = true.
On Load event: Here is where your setup code, set variables, possible set controls etc. is to occur. So you can't modify controls in on-open - too soon of a event, but you CAN modify the forms controls and values in the on-load event.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.