How to prompt user to input data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I have a check box, that when ticked, requires a text box to have a currency
figure input.. I want to set up the check box so that the user cannot proceed
without filling in the currency field.

Is there a way to do this???
 
Yes, this can be done, but there is a problem with it. If you set up the
check box so that when you check it the user can't proceed without entering
a value in the textbox, then the user also can't uncheck the checkbox if
they change their mind.

A better approach may be to just move the focus to the textbox upon checking
the checkbox as a hint to the user. In the form's BeforeUpdate event, check
the value of the checkbox and if it is checked, check the value of the
textbox for a valid value. If it's not there, Cancel the update and prompt
the user using a Msgbox.
 
Wayne

I have done something similar with a combo box where it asks the user if
they want to proceed (Yes/No) How Would I do this? Also Could I have the code
highlight the currencey box to red to prompt the user??
 
It depends on where the user is proceeding TO. If the user is to proceed to
other controls that depend upon the data in the text box, then you could
disable the other control(s) if CheckBox1 is True and Text1 is Null and then
enable them when Text1 is no longer null (probably in the CheckBox1_Click and
Text1_AfterUpdate events).

If the next action is for the record to be saved, just do an integrity check
in Form_BeforeUpdate (e.g. If CheckBox1 and Text1 = Null Then...) and issue a
Cancel as necessary. In fact, you could just wait until the BeforeUpdate

If you want to get really fancy, you could use an InputBox after
CheckBox1_Click and then simply not allow the user to continue until a value
has been entered. When it is entered, transfer its contents to the currency
box.

Private CheckBox1_Click
If CheckBox1 Then
Do While IsNull (CurrencyBox)
CurrencyBox= InputBox ("Enter amount" )
Loop
Else
CurrencyBox = Null
End If
End Sub

This forces the user to enter the amount into a popup InputBox, but then
transfers the information into the CurrencyBox.
 
To highlight the currency box in red, just change the back color of the box.
Changing the fore color won't work because you haven't typed anything into
it yet.

Me.txtCurrency.BackColor = vbRed

If you prefer a different color, open the form in design mode, click on the
textbox and open the Properties dialog, then go to Back Color on the format
tab. Pick you desired color then copy and paste the resulting number into
the code in lieu of vbRed.

To prompt the user when they try to leave the currency box to see if they
really want to, then using the currency box's Exit event you would enter
something similar to:

If MsgBox("Exit?", vbQuestion + vbYesNo) = vbNo Then
Cancel = True
End If
 
Brian I have Tweeked the code to show the correct Checkbox names & text box
names, but the code does not bring up a input box as follows:-

Private Sub InsuranceSold_Click()
If InsuranceSold Then
Do While IsNull(Insurance_Premium)
Insurance_Premium = InputBox("Enter Insurance Premium")
Loop
Else
Insurance_Premium = Null
End If
End Sub

With InsuranceSold being the checkbox and Insurance_Premium being the text
box which is supposed to be populated with the input box. Can you advise what
I am doing wrong???
 
The InputBox will only be brought up if InsuranceSold is checked (True) and
Insurance_Premium is Null. Are you sure that the value of Insurance_Premium
is Null and not a zero length string? Try stepping through the code and when
you get to the Do While line, hold the mouse cursor over the text
"Insurance_Premium". The value should popup in a tooltip. If the value could
be either Null or a zero length string, you may want to try

Do While Nz(Insurance_Premium, "") = ""
or, if the value is a number, not text
Do While Nz(Insurance_Premium, 0) = 0

Also, is there anything else called Insurance_Premium, other than the
textbox, that the code may be mistakenly getting a value from? Do you have
Option Explicit in the top of the module where Option Compare Database is
at? If not, add it below or above the Option Compare Database line and then
try to do a compile (Debug|Compile...). If you have any typos that the code
doesn't recognize as controls or declared variables in that module then the
compiler will now find them. I recommend that you add this line to all
modules you've already created and also go to Tools|Options in the code
editor and check the box next to "Require Variable Declaration".
 
Wayne

I have managed to get the input box to appear ok (your changed code works)

However it does not populate the Insurance_Premium field once you hit <Enter>

Here is a copy of the modified code:-

Private Sub InsuranceSold_Click()
If InsuranceSold Then
Do While Nz(Insurance_Premium, 0) = 0
Insurance_Premium = InputBox("Enter Insurance Premium")
Loop
Else
Insurance_Premium = Null
End If
End Sub

Like I said, the input box now appears but does not populate the value into
the Insurance_Premium field.

I do not have option explicit on the code, however I do not have any other
text box called Insurance_Premium!!???!!
 
Where is Insurance_Premium located, on this form, another form, a subform?
Is Insurance_Premium the name of the control, the field it is bound to, or
both?
 
Wayne

The Field resides in the Data Entry form (which is this form).

Insurance_Premium is the identifier name and InsurancePremium is the control
source (as per the textbox properties)
 
In that case, the only thing I can think of would be that the loop is
running before the textbox updates its value, so the value is still Null and
the input box opens again. You may want to test the Text property of the
textbox instead of the Value of the textbox. To do this, the textbox will
have to have the focus.

If InsuranceSold Then
Me.Insurance_Premium.SetFocus
Do While Nz(Insurance_Premium.Text, 0) = 0
Insurance_Premium = InputBox("Enter Insurance Premium")
Loop
'etc.

If that doesn't work, try the InputBox statement without the loop and see if
it works by itself.

If InsuranceSold Then
'Me.Insurance_Premium.SetFocus
'Do While Nz(Insurance_Premium.Text, 0) = 0
Insurance_Premium = InputBox("Enter Insurance Premium")
'Loop
'etc.
 
Wayne

The input box does not open again. The input box pops up. I type in the
insurance premium in the input box and click OK. The input box disapears, but
the Insurance premium field is not populated with the figure that I placed
into the input box.

Hope this has not confused you!
 
Please zip and send me a copy of the database at (e-mail address removed). Attach
a note telling me where to look.
 
Back
Top