Message prompt when closing a form

  • Thread starter Thread starter Billf from Oz
  • Start date Start date
B

Billf from Oz

Hi,

I have a main form "A" that opens up to a form "B". Both forms need to be
completed and are linked to each other by a reference number. My issue is
that some users input data in form "A" then open up form "B" but do not input
any data. It is imperative that form "B" gets completed. I would like a
message box to pop up when the user clicks on the "Return" button in form "B"
to alert them to enter some data and stop the form from closing until data is
entered. Once data in entered, they should be able to return to form "A".
 
On Mon, 1 Dec 2008 19:01:01 -0800, Billf from Oz

The Form_Unload event is the ideal place to do that, because you can
cancel that event, effectively stopping the form from being closed:
if not AllImportantFieldsFilledOut() then
Cancel = True
end if

private function AllImportantFieldsFilledOut() as Boolean
'Check if the important fields FirstName and LastName have been filled
out
dim blnResult as Boolean
blnResult = True 'optimistic
if IsNull(Me.txtFirstName) then blnResult = False
if IsNull(Me.txtLastName) then blnResult = False
AllImportantFieldsFilledOut = blnResult
end function

-Tom.
Microsoft Access MVP
 
Hi Tom,

Thank you for your reply. Your solution seems exactly what I am looking for.
I may be doing something wrong in building the code for my form as I get a
compiler error when I try to run the code. I copied you code and substituted
the "important fields" to the relevant fields that need to be entered. I go
to the form properties and build the code in the "On unload" property. The
module appears with the Private Sub On Unload heading. I copied your code
between the heading and End Sub. It is at this point I get the compiler error
when I run the code. Apologies for my ignorance, but I can't figure out what
I am missing.

Thanks again.

Bill
 
Back
Top