Locking the focus of a control until some data is entered in that control

mark curtis

Registered User.
Local time
Today, 07:46
Joined
Oct 9, 2000
Messages
457
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
 
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).]
 
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
 

Users who are viewing this thread

Back
Top Bottom