Full Version: Mandatory fields on Excel Form
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
loco_breath
Hi
I have designed a form template in Excel that users will fill out. Is there any way to specify certain fields as mandatory and prompt the user with a warning if they try to save or close the document without filling in these fields?
Ideally, I would like a situation where the form cannot be closed unless certain fields are filled in and for all the other (mandatory) fields, Excel shows up a warning...
Thanks
Krishna
PaulBrand
Try something like this:-
ub Auto_Close()
If Sheets(3).Range("A1") = "" Then
MsgBox "No"
Exit Sub
End If

End Sub
loco_breath
Cheers Paul.
The above code prompts the user but still lets him close the file wihtout populating the field. What would I need to add to this to make the system force the user to populate the field before it lets him close the file?
PaulBrand
I used the wrong event.
The Cancel = True bit keeps the book open.
In the VBE window under 'This Workbook' use this kind of code, you can also set cell properties so they appear differently ( red border or something)
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets(3).Range("A1") = "" Then
MsgBox "No"
Cancel = True
End Sub
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.