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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

avoiding access MsgBoxes after my Own MsgBox

Status
Not open for further replies.

sanan

Technical User
Apr 15, 2004
139
IR
Hi there
I have a form with Access as FE and SQL as BE, I have some codes in my Before Events of my form. Which is working sort of fine, But here is my problem after I get my msgBox with a vbyes and vbNo option, after for example pressing the yes Button, I get the access MsgBox “off course it has my Application Name as it’s Title” Which basically asks the same question of my original MsgBox and it indicates that the Following Data or Records can not be saved and etc… with the a yes and No button to press.
Since this msgBox is sort of Identical to my first original MsgBox can I avoid it?
Otherwise I do not want to see this access msgBox, Is this Possible? And if it is, How can I do it?

Best Regards
sanan
 
You may consider playing with the UnDo method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Could you not use

Code:
DoCmd.SetWarnings False

Im not sure i understand hope it helps anyway
 
Hi PHV, maverickmonster
Thanks for your comment.
PHV good to see you here, But I do not think that I quite understand what you are trying to say. Could you please explain a little more.

maverickmonster; Also I tried your technique, But no success, Here is the BeforeUpdate Event of my form, The I would provide complete Text of the of the Warning msgBox, that I get;

Private Sub Form_BeforeUpdate(Cancel As Integer)
DoCmd.SetWarnings False ‘I added your suggestion, But no success’
Dim strMsg As String
Dim MyResp As Integer
strMsg = "Press Yes, To Close the Form"
strMsg = strMsg & vbCrLf & "Press No, And Continue By Choosing a Custumer!"
If IsNull(Me!ComboCustomer) Or IsNull(Me!InvoiceID100) Then
Cancel = True
MyResp = MsgBox(strMsg, vbYesNo + vbQuestion, "Save Issue")
If MyResp = vbNo And IsNull(Me!ComboCustomer) Then
Me.ComboCustomer.SetFocus
ElseIf MyResp = vbNo And IsNull(Me!InvoiceID100) Then
Me.InvoiceID100.SetFocus
End If
Else
DoCmd.Close acForm, "sales", acSaveNo
End If
End Sub

After I get MyResp MsgBox, and If I press yes for example, I do get another MsgBox with a warning sign and my Application Name for it’s Title with following Texts;
You can’t save this record at this time!
Inventory100 may have encountered error while trying to save a record.
If you close this object now, data changes you made will be lost.
Do you want to close the Database object anyway?
Yes No
If I have pressed yes in my Original MsgBox I have to press yes again to accomplish what I wanted to do in first place. The same with No Button, I have to Press No again.

Best Regards
Sanan
 
Hi maverickmonster
I should say that the record source of the above form is a query names "Sales query" with a unique Table called "Tablesales"
The only required field in my TableSale is a field by Name of salesID, and the cnotrol name is the same, In actuallity this control it's visibility is et to No and it's locked is yes.

Best regards
Sanan
 
There are a couple of things here that I'm not comfortable with using myself, like using the close method in the forms before update event. But that's another story.

From what you've described, it seems what triggers the before update event in this case, is a user hitting either the x in the upper corner, or another type of close form command.

In such case, using cancel = true, will only prevent the save, and leaving the record in it's unsaved state, triggering form errors in the continued close process. In such case, you will need to Undo the record to avoid it (as PHV has alredy stated).

I would probably rather remove the x button of the form, and force the users to use my custom close button, and in that code trap whether the before update succeded or not, and if not, not close the form (not issue the close command).

See for instance thread702-866344 for some sample code (the version without mfclose, perhaps). Using that approach, your before update, could then perhaps look something like this:

[tt] Dim strMsg As String
Dim MyResp As Integer
strMsg = "Press Yes, To Close the Form"
strMsg = strMsg & vbCrLf & "Press No, And Continue By Choosing a Custumer!"
If IsNull(Me!ComboCustomer) Or IsNull(Me!InvoiceID100) Then
MyResp = MsgBox(strMsg, vbYesNo + vbQuestion, "Save Issue")
if myresp=vbyes then
me.undo
else
cancel=true
if isnull(Me!ComboCustomer) then
Me!ComboCustomer.setfocus
else
Me!InvoiceID100.setfocus
end if
end if
end if[/tt]

- typed not tested - a little indentation of the code makes it a bit more readable, and maintainable...

Roy-Vidar
 
Hi RoyVidar
Thanks for your excellent Comment.
I used your Codes Exactly, and also different version my own codes, But The best I could achieve was avoiding the Access msgBox only in case the user presses Yes, but The No still remains.
Also I am a little confuse on where to put the following codes, Let’s try it on your codes since That is what I am using Now;
if dataerr = 2169 then
response = acdataerrcontinue
end if

And finally about closing a Form with a close Button other that access close button.
Again I am a little confuse, Let’s say we have a form called F1 and we have a Close Button on it by name of
“cmbclose” Now could you please tell me about the codes that goes into The
Form_before Update Event, and the codes that Goes into cmbClose_Click(), and Where do you put this sub “Private Sub myclose()” , and What about the “Public mfClose As Boolean” what control or Events does this belong to.

Best regards
Sanan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top