Remember this is to link the Orders Form with the customer on existing customers AND NEW customers also.
Me.CustomerID = Forms!Orders.CustomerID
Me.CustomerID = Forms!frmOrders.CustomerID
if me.dirty then me.dirty=false
The Orders Form will pop up and have the Customer ID automatically matching the Customer ID from the Customers Form I was previously on. Without me having to use the dropdown combobox. Correct??That would be the hope :)
Private Sub Form_Load()
Me.CustomerID = Forms!frmCustomers.CustomerID
End Sub
Private Sub btnUndoRecord_Click()
Me.Undo
DoCmd.Close acForm, "frmOrders", acSaveNo
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
'161003 strive4peace
'-------------- make sure required data is filled out
With Me.ControlName 'substitute your control Name (ideally, the same as the field name in the Control Source)
If IsNull(.Value) Then
'if it is not filled out, then move the focus to that control
.SetFocus
'give the user a message
MsgBox "You must enter WHATEVER", , "Missing Data" 'substitute Whatever
'IF this is a combobox, drop the list for them - uncomment next statement
' .Dropdown
'don't save the record yet
Cancel = True
'if you want to undo the record, uncomment next statement
'Me.Undo
'quit checking and give them a chance to fill it out
Exit Sub
End If
End With
'if you have a field in the table to keep track of when a record was modified, uncomment next statement
' Me.dtmEdit = Now()
End Sub
I call the field to keep track of when a record was added dtmAdd and the field to keep track of when it was edited dtmEdt. Both have a DefaultValue =Now()'-------------- make sure required data is filled out
With Me.ShipAdd1 '
If IsNull(.Value) Then
'if it is not filled out, then move the focus to that control
.SetFocus
Private Sub Form_Load()
Me.CustomerID = Forms!frmCustomers.CustomerID
End Sub
If you aren't getting it to work ... is it that you are not seeing the value right away? It may be going into the table ... check after you test. Refresh Records if the table was already open
anyway, I think a better place would be on the AfterInsert event just in case the user changes their mind about creating a record
Alternatively, I think you can also put what Scott mentioned in the DefaultValue property for the CustomerID control (Visible=No), prefaced with =
be sure before you open a form, you save the record you are on if it is dirty (has unsaved changes)
Open in new window
it is best to test IF a record needs to be saved and only save it if needed.