Setting Yes/No values in Code

Gastank

Registered User.
Local time
Today, 13:50
Joined
Aug 5, 2002
Messages
12
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
 
Not sure if this will solve the whole problem but I did notice something:

If Response = vbYes And (Me!txtItemCode) Is Not Null = True Then ' User choses Yes

Should read:

If Response = vbYes And Not IsNull(Me!txtItemCode) Then ' User choses Yes
 
GasTank,

I think your syntax should be something like:


If (Response = vbYes) And Not IsNull(Me!txtItemCode) Then

instead of:

If Response = vbYes And (Me!txtItemCode) Is Not Null = True Then ' User

hth,
Wayne
 
Rob, Wayne
thanks for your quick replies, I'll try your suggestions and hopefully solve my problem - many thanks
 
Rob, Wayne,

I suspect you both knew your suggestions were spot on and I thank you for solving my problem, many thanks
 

Users who are viewing this thread

Back
Top Bottom