mark curtis
12-12-2000, 02:39 AM
Dear Experts,
How do I lock a control until it has been populated and inform the user via a message box that they have to fill the control in or they can not fill in any other controls on the form.
eg if no data entered then Message, then set focus back to control.
Thanks
Mark
Depending on number of controls:
Set the over control to locked or not visible, on "after update" event of your main control:
Control1.locked = false
Control2.locked = false ...
or
Control1.visible = true ...
Then "On current" event of your form:
MainControl.Setfocus
Control1.locked = true ...
or
Control1.visible = false ...
Another way is to use this code on "On select" event of all your controls:
if maincontrol & "A" = "A" then
msgbox "Input data in Maincontrol"
maincontrol.setfocus
end if
Talismanic
12-12-2000, 07:49 AM
You could put this in the On_Exit event or what ever event works for you in your situation:
Dim Answer As Variant
If IsNull(Me.YourControlName) Then
Answer = MsgBox("The text box can not be left blank", vbOKOnly, "Hey You!")
If Answer = vbOK Then Cancel = True
Exit Sub
Else
' Do next step
End If
If you don't need the Else just End the If and it will exit the sub when the field has data.
[This message has been edited by Talismanic (edited 12-12-2000).]
Pat Hartman
12-12-2000, 06:37 PM
You have a choice. You can write a lot of code or you can write a small amount of code. My personal choice is as little code as possible. That way I don't have to write it. I don't have to test it. And, I don't have to debug it.
In the BeforeUpdate event of the FORM put code that checks the field in question for a valid value. If it has none, cancel the update event, display a message box, and set the focus back to the field you want them to enter data into.
If IsNull(YourFld) or Len(Trim(YourFld)) = 0 Then
Cancel = True
MsgBox "Please enter data in YourFld before proceeding", VBOKOnly
Me.YourFld.SetFocus
End If
Your alternative is to put similar code in EVERY control on the form! Or, even worse, enabling and disabling controls one by one to force them into a specific navigation path through the data entry. UGH!
mark curtis
12-12-2000, 10:51 PM
Thanks for the replies but still have a slight problem that when I close my form the message box is still visible and I have to press it 4 times to make it go. Any clues???
Thanks