PDA

View Full Version : Conditional checking



wasim_sono
01-24-2007, 11:28 PM
Dear All

I m facing problem to check criteria on another field. Lets start here.

Fields name:
=========

Zone (data accepts as 01, 02, 03, ......21)
Series ( data accepts as 1000, 2000, 3000, 4000, 5000, 6000,....9000)
......
.....
Amount
Ac1 (data accepts as 301, 302, 303,.......319)
Ac2 (data accepts as 301, 302, 303,.......319)
Ac3 (data accepts as 301, 302, 303,.......319)
Ac4 (data accepts as 301, 302, 303,.......319)
Ac5 (data accepts as 301, 302, 303,.......319)
Ac6 (data accepts as 301, 302, 303,.......319)

tab order:
======
1=Zone, 2=Series, .........16=Ac1, 17=Ac2....

Criteria checking:
============

If Series = 1000 then Ac1=301 or 302 only
if series = 2000 then ac1=301 or 303 or 305 only
if sereis = 3000 then ac1 = 302 or 304 or 310 or 305 only
.......
......
.....
I used the following code on after update event of AC1 as under:

Private Sub AC1_AfterUpdate()
Dim Series As String
Series = Me.SER.Value
' Me.SER.SetFocus
If Me.SER.Text = "1000" Then
Me.AC1.DefaultValue = "301" Or "302" Or "303" Or "319"
'If Me.AC1.Text <> "301" Or "302" Or "303" Or "319" Then
MsgBox "Code is incorrect"
End If
' ElseIf Series = 4000 Then
'Me.AC1.Text = 301 Or 310

'End If

End Sub

but I got the following run time error message.


Run-time error '2185'
You can't reference a property or method for a control unless the control has the focus.
for this I use the following code

' Me.SER.SetFocus


but still not getting the result.

any one can help me.


Thanks in advance.

OBP
01-25-2007, 04:25 AM
wasim, I am not sure that this is the best way to do what you want.
First of all I have reservations that when you have more than one "option" for a field that the default value is the best place to try and set it.
Wouldn't it be better to set the row source of a Combo box based on the entry in the "Series" field. When someone selects "1000" the combo would only have 301 and 302 in it's list.
The combo box would be "bound" to the Ac1 field.

wasim_sono
01-26-2007, 03:10 AM
Thanks for the reply. But will u tell me how bound the combo box with AC1 field. and we have to bound Six fields from AC1 to Ac6 with combo box bcaz user may enter in all of fields or any five or any four or any three etc.

OBP
01-26-2007, 05:49 AM
When you create a Combo Box using the Toolbox Wizard it will ask you if you want to store the selection for later and then it will ask you if you want to store the data in a field on your Form, for Ac1 you would choose Ac1 etc.
You can also set the "Bound Field" after the Combo has been created using the Combo's Property "Bound Column" and "Control Source".
The bound column is the column that contains the data to be stored and the Control Source is the field where you wan to store it.
Yes you will need as many Combos as you have Fields to enter data in to.
The actual fields where the data is going to be stored do not need to be Visible on the Form, just on the form.