PDA

View Full Version : Validating the input fields



sindhuja
08-06-2008, 07:10 PM
:doh:
Hi All,

Is there a way to validate all the textboxes, comboboxes, radiobutton and the checkbox all at once. If no value has been entered in any of these in the access forms then an error message to be displayed.

Also i need to retrieve the value of radiobutton in a group. I tried but its giving the value either as 0 or 1. Am not sure how to save the value of radiobotton to a table (yes / No). Similar is the case with checkbox...


Any help on this will be highly helpful...

-Sindhuja

CreganTur
08-07-2008, 05:13 AM
If a field is setup as yes/no in the table, the it automatically becomes a checkbox when you drag the field's name from the field list onto your form.

If you want to use a radio button instead of a checkbox, then all you need to do is set the control source of the radio button to the name of the yes/no field you want to work with. A filled radio button = yes, an empty radio button = no.


Also i need to retrieve the value of radiobutton in a group.

If your radio buttons are in an option group, then you need to get the value of the option group, not the individual buttons. If the first radio button is filled, then the option group should = 1; if the second button is filled then the option group should = 2, etc.


Is there a way to validate all the textboxes, comboboxes, radiobutton and the checkbox all at once.

There may be a better way to do this, but I use a series of If statements to evaluate the values of form objects.

sindhuja
08-11-2008, 03:44 PM
Thanks for the information !!!!

Any update on how to validate all the input fields (text box, radio button, combobox and the check box) in access form before submitting the datas on button click.

Coding on this will be highly helpful...

-Sindhuja

OBP
08-12-2008, 02:46 AM
sindhuja, why do you need to validate them all at once?
Are you using an "Unbound" form?
If you are using a bound form you can use the "On dirty" event to identify if anything has been entered or changed in any of the fields on the form.
With a bound form you do not need a "button click" to submit the data, Access does it automatically IF something has been entered.

CreganTur
08-12-2008, 05:16 AM
Any update on how to validate all the input fields

Personally, I just use If statements to validate the value of the textboxes. For instance, if something cannot be null, then I would use:

If IsNull(Me.Textbox) Then
MsgBox "All required fields must be filled in."
Me.Textbox.SetFocus
Exit Sub
End If

Basically you just need to decide what things you need to check for, and then write some If or Select Case statements to cover these eventualities.

sindhuja
08-12-2008, 08:28 AM
Hi OBP,

Am using "Unbound" form..

-Sindhuja

OBP
08-12-2008, 09:03 AM
Can I ask why?
With an Unbound Form you will have to go with Randy's code for testing each control seperately.

sindhuja
08-12-2008, 03:30 PM
I tried using Randy's suggesion. All set with the text box validations....
for the checkbox, radio buttons and the combobox i need to check.

i thought checking controls all at once with a global message will be time consuming...

Also, is there a way to check the controls in the form by its own without me specifying the name and check using IF condition. If the controls are less then well and good using IF statement... Suppose if more controls in a single form using if statement will be bit difficult...

let me know your thoughts....

-Sindhuja

sindhuja
08-12-2008, 03:59 PM
One more query !

To find the value of option group i have used the below line...

Sub value()
Dim a As String
Dim b As String
a = Me.cboprocess.Column(1)
MsgBox a

'option group named grp2

b = Me.grp2.value
MsgBox b
End Sub

Its giving me the value of "1" if i select YES button and the "2" if i select NO option. Its not giving me the value as YES or NO.

Not sure where am going wrong...

-Sindhuja

OBP
08-13-2008, 02:49 AM
You are not doing anything wrong, that is how an Option Group works, it returns the Value of the "Option" chosen not the "Text" label.

sindhuja
08-13-2008, 10:22 AM
Hi,

I tried this coding to validate all the controls at once? but its showing me the below error.

"Runtime error 438: Object doesn't support this property or method"


Private Sub cmdgrp1save_Click()
With Me
For Each Ctrl In Me.Controls
If Ctrl.Value = vbNullString Then
MsgBox "You must complete all entries"
Ctrl.SetFocus
Exit Sub
End If
Next Ctrl
End With
Set Ctrl = Nothing
End Sub


Any help on this will be helpful...

-Sindhuja

OBP
08-13-2008, 10:28 AM
If you have any Command Buttons on the Form they do not have any value.
Try putting a message box in there that will give you the Controls "name" as you step through them to see which one causes the error.

sindhuja
08-20-2008, 03:42 PM
hi,

Am still struck up with this...
can anyone please help me out in validating an option group with two radio buttons. I want to check whether user has selected the value. If so, retrieve the value to the variable. Similar is the case for check box...

Any coding on this...
i tried out many ways but its not wkg for me...

-Sindhuja

darthobra
08-21-2008, 06:53 AM
sindhuja,

In your loop through the controls, test for the control type as text box and then validate the value. When validating the value you might consider testing for Null, empty strings ("") and incorrect data type.

sindhuja
08-21-2008, 04:00 PM
hi,

Am all set with validating the textbox.. have used Randy code and works fine in case of textbox.

But i want to validate the radioobuttons in option group , checkbox... and retrieve the values for the same..

-Sindhuja

darthobra
08-21-2008, 05:23 PM
sindhuja,

Hey there...

You determine the option values by selecting the radio button in design view, going to properties and under data, set the "Option Value". this is what will be returned on the Frame_Click event. In Access, true equates to -1 and false equates to 0. A checkbox is the same, checked equates to -1 (true) and unchecked equates to 0 (false).

I hope this helps.

CreganTur
08-22-2008, 05:23 AM
If your radio buttons are inside an option group, then you need to check the value of the option group, not the individual buttons. The value that's returned is a number that represents the order of the radio buttons in the option group.

Example: You have an option group named optGroup, with 3 radio buttons. If the 2nd button is selected, then when you check the value of the option group you'll find that optGroup = 2. If you had chosen the first button, then optGroup = 1, etc.

Checkboxes are easier- you can check them directly- you need to check for Null, True, and False. True means it is checked, false means it is unchecked, and null means that the button has not been touched at all- this generally happens if you don't set a default value for the checkbox.