Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double-click Yes/No button? 2

Status
Not open for further replies.

bikerted

Technical User
Nov 7, 2003
221
GB
The button on my InputPayer form works succesfully with the following procedure, but I seem to have to double-click either button before the form will close and the conditions (when satisfied) cause the code to execute:

Dim intnewrec As Integer
intnewrec = Form.NewRecord
If intnewrec = True And MsgBox("Do you wish to Input this Payer?", vbYesNo, "Required Field Warning!") = vbNo Then
Cancel = True
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
ElseIf intnewrec = False And MsgBox("Do you wish to Input this Payer?", vbYesNo, "Required Field Warning!") = vbNo Then
Cancel = True
Else
DoCmd.RunCommand acCmdSaveRecord
Forms!ReceiptsInput![Payee ID] = Me!Text36
Forms!ReceiptsInput.Refresh
End If
DoCmd.Close

No doubt there's is a fatal flaw, but being a total novice I can't see it. In fact it was a miracle I got this far! So if anyone can assist I should be, as ever, most grateful.

Ted
 
You have a message box in twice. Why are you checking for a new record when it does not seem to make any difference to your code?
It is a good idea to post marked-up code [ignore]
Code:
[/ignore] (see TGML link below).
 
Thanks Remou - for both comments/advise.

So I tried this with obvious results:
Code:
Dim intnewrec As Integer
intnewrec = Form.NewRecord
If intnewrec = True And MsgBox("Do you wish to Input this Payer?", vbYesNo, "Required Field Warning!") = vbNo Then
Cancel = True
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
ElseIf intnewrec = False Then
Cancel = True
Else
DoCmd.RunCommand acCmdSaveRecord
Forms!ReceiptsInput![Payee ID] = Me!Text36
Forms!ReceiptsInput.Refresh
End If
DoCmd.Close

When I select an existing record on the InputPayer form and click Yes or No, nothing is copied to Payee_ID.

Basically, all I want to do is give the user a final chance to either accept and copy a newly created record or an existing one, or not. The undo action works with the new record, but of course generates an error with existing records. The solution eludes me at the moment.
Ted

 
Stripping back your code, you have:

[tt]If intnewrec = True
Cancel = True
ElseIf intnewrec = False
Cancel = True[/tt]

Life is a lot easier if you indent:
Code:
Dim intnewrec As Integer
intnewrec = Form.NewRecord
If intnewrec = True 
    If MsgBox("Do you wish to Input this Payer?", vbYesNo, "Required Field Warning!") = vbNo Then
       Cancel = True
       'This line has gone out-of-date, look at RunCommand
       DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    Else
       DoCmd.RunCommand acCmdSaveRecord
       Forms!ReceiptsInput![Payee ID] = Me!Text36
       Forms!ReceiptsInput.Refresh
    End If
End If
'Not sure where this should be, it depends on your app.
DoCmd.Close


 
What about this ?
If MsgBox("Do you wish to Input this Payer?", vbYesNo, "Required Field Warning!") = vbNo Then
If Me.Dirty Then Me.Undo
Else
Me.Dirty = False
Forms!ReceiptsInput![Payee ID] = Me!Text36
Forms!ReceiptsInput.Refresh
End If
DoCmd.Close

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks guys. Remou, a syntax error came up, but upon adding Then after the first If statement the code worked for new records, but not for existing. PHV, the code worked fine. The only thing I didn't account for is if one tries to enter a Null value. I'm unsure about how to insert my own message as opposed to the debug dialog. Would one nest something like this: "If Me.Text.36 Is Null.. End If" before the Else?

Ted.
 
If MsgBox("Do you wish to Input this Payer?", vbYesNo, "Required Field Warning!") = vbNo Then
If Me.Dirty Then Me.Undo
ElseIf Trim(Me!Text36 & "") = "" Then
MsgBox "You can't input a null player"
Me!Text36.SetFocus
Exit Sub
Else
Me.Dirty = False
Forms!ReceiptsInput![Payee ID] = Me!Text36
Forms!ReceiptsInput.Refresh
End If
DoCmd.Close

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That's great PHV. I deleted the line Me!Text36.SetFocus because an error message came up indicating that one couldn't set focus on this control. No matter, because it automatically focuses on the preferred control.

So many, many thanks once again for your time and effort.

Ted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top