I hope the experts can help me.
I have a main form with a text box control [txtDiscrepancy] formatted as a Yes/No field with a default value set to No.
On a subform I enter details of any shipment discrepancies using 3 textboxes - [txtItemCode] - [txtQtyAdvised] - [txtQtyReceived]. I have tried to create a "save" button that will firstly prompt "do you wish to save Record" and secondly ensure that the [txtItemCode] control has a correct value. If everything is in order then the code should save the record and also change the Main form control value of [txtDiscrepancy] form No to Yes. However, if the [txtItemCode] does not contain a value (Is Null?) then the code does not update the record or change the main form control and displays an alternative message "Item Code Required". I tried the code below but get the dreaded "Object Required" error message Idon't know where to go from here, can anyone please point me in the right direction? T.I.A.
Private Sub btnSave_Click()
On Error GoTo Err_btnSave_Click
Dim Msg, Style, Title, Response
Msg = "Do you wish to save this record?" ' Define Message.
Style = vbYesNoCancel + vbQuestion + vbDefaultButton2 ' Define Buttons.
Title = "Update Discrepancy Form" ' Define Title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes And (Me!txtItemCode) Is Not Null = True Then ' User choses Yes
DoCmd.RunCommand acCmdSaveRecord ' Save Record.
Me.Recalc ' Recalc
Forms!frmGoodsReceiving!Discrepancy = "Yes" ' Change main form control from default No to Yes
Else
MsgBox "ItemCode Required" ' Display prompt to enter details in Textbox
Exit Sub
End If
Exit_btnSave_Click:
Exit Sub
Err_btnSave_Click:
MsgBox Err.Description
Resume Exit_btnSave_Click
End Sub
I have a main form with a text box control [txtDiscrepancy] formatted as a Yes/No field with a default value set to No.
On a subform I enter details of any shipment discrepancies using 3 textboxes - [txtItemCode] - [txtQtyAdvised] - [txtQtyReceived]. I have tried to create a "save" button that will firstly prompt "do you wish to save Record" and secondly ensure that the [txtItemCode] control has a correct value. If everything is in order then the code should save the record and also change the Main form control value of [txtDiscrepancy] form No to Yes. However, if the [txtItemCode] does not contain a value (Is Null?) then the code does not update the record or change the main form control and displays an alternative message "Item Code Required". I tried the code below but get the dreaded "Object Required" error message Idon't know where to go from here, can anyone please point me in the right direction? T.I.A.
Private Sub btnSave_Click()
On Error GoTo Err_btnSave_Click
Dim Msg, Style, Title, Response
Msg = "Do you wish to save this record?" ' Define Message.
Style = vbYesNoCancel + vbQuestion + vbDefaultButton2 ' Define Buttons.
Title = "Update Discrepancy Form" ' Define Title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes And (Me!txtItemCode) Is Not Null = True Then ' User choses Yes
DoCmd.RunCommand acCmdSaveRecord ' Save Record.
Me.Recalc ' Recalc
Forms!frmGoodsReceiving!Discrepancy = "Yes" ' Change main form control from default No to Yes
Else
MsgBox "ItemCode Required" ' Display prompt to enter details in Textbox
Exit Sub
End If
Exit_btnSave_Click:
Exit Sub
Err_btnSave_Click:
MsgBox Err.Description
Resume Exit_btnSave_Click
End Sub