Full Version: Custom Form as Message Box
UtterAccess Forums > Microsoft® Access > Access Forms
access8577
I created a form to serve as a message box rather than using the ones that Access generates. This form warns users that a record with the same contract number already exists in the database and prompts them to continue saving the record or abort. How can I pass the result of this form (Yes or No) to the entry form so that the record is saved or the focus is set to the contract number control depending on the button that they click? The custom message box form is DuplicateContract and has two buttons (YesButton and NoButton). I have the save button code below:
im saveContract, db, rs, strsql
saveContract = True 'Flag to determine whether or not to process the save action
If addFlag = True Then ' this is a new record
Set db = CurrentDb
strsql = "select count(contract_id) as contract_count from contract where contract_id=" & [Forms]![contract]![ContractCombo]
Set rs = db.OpenRecordset(strsql, dbOpenSnapshot)
If rs!contract_count > 0 Then
stDocName = "DuplicateContract"
DoCmd.OpenForm stDocName, acNormal, , StLinkCriteria, acFormEdit, acDialog
End If
db.Close
End If

If saveInvoice Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
jmcwk
You may want to have a look at This link as an alternative it also includes a tutorial. Basically what it provides is notification to the user that a Duplicate record exists and then open the record.
TH
access8577
Thanks but I've already scoped it out and don't like the method that much. Basically what is happening is the users are clicking through the button without actually reading it so I created a giant obnoxious form with a stop-sign in the middle that gets the point across.
jmcwk
Good Deal ! Glad you worked it out and Good Luck with your project sad.gif
access8577
Haven't got the problem worked out yet, still need to figure out how to pass the form results (Yes or No) to the data entry form.
access8577
bump
JVanKirk
I would assume you have one command button for Yes and one for No on your popup form. If the click Yes to continue, then just close your popup form:
oCmd.Close
The record will be saved once you move to the next record or close the form. If you want to, you can close both forms after they click yes, but then if they want to add additional records, they have to reopen the form. You could also move to a new record after you close the popup form:
DoCmd.Close
Forms!frmYourFormName.ContractNoControlName.SetFocus
DoCmd.GoToRecord acnewRecord
If the click No, then just use the first two lines from above.
If your form is bound, you don't need a "save" button, moving to the next record commits the changes or additions you make to a record. I would consider adding the events above in the OnExit event of the ContractNo control, so as soon as they enter the contract number and move to the next field(or try to) they get a message that it is duplicate. Then you modify your Yes button to be:
DoCmd.Close
Forms!frmYourFormName.TheNextControl.SetFocus
and your no button stays as :
DoCmd.Close
Forms!frmYourFormName.ContractNoControlName.SetFocus
Hope that helps...
J
JVanKirk
bump sad.gif
access8577
Hehe, nice bump...I tried it out but I get a can't disable control while it has the focus error because the second part of the code locks all of my controls to prevent unwanted editing. Basically the database has to have safeguards in place like a "save" button so that information that is modified is done so deliberately. I'm thinking that I would need to declare a public variable in the DuplicateContract screen and set the value depending on which button the user clicks and then use a select case statement in the save button routine?
JVanKirk
Is your form bound? If Yes, then what happens when the user closes the form if they haven't hit the save button? Do you run any kind of Undo? If your form is bound, and they make changes and then close, the changes are saved.
Are all of your controls locked when you open the form. Maybe if we could step through this from start to finish we'll get to the solution quicker.
What happens when you open the form, what is the state of the controls?
At what point do you want Access to check to see if the entered Contract Number is duplicate? I would want this upon leaving that control, but everyone has their own preferences.
Break it down a little so I can get a grasp on the flow and we can get this figured out. What you want isn't hard, I didn't know you were locking control. What I gave you already should work. What you could do is add one control to your form, an unbound textbox, size it so it is basically 0" by 0", then, set your focus to that control before disabling all your other controls.
J
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.