Hello, I generally just use search and can find help to what I am looking for ....

mdschuetz

Nerd Incognito
Local time
Today, 11:46
Joined
Oct 31, 2007
Messages
49
However, this one eludes me.

On a FORM, I have 2 Objects. A check box and a combo box.

checkTax
cboAccount

I have checkTax set to: YES/NO

I have cboAccount functions with a rowsource lookup: SELECT Accounts.* FROM Accounts;

Here is the layout...

6100-0000 = NO
6200-0000 = NO
5430-0100 = YES
5475-0100 = YES

Now if I select 6100-0000 or 6200-0000 in my drop down list in the combo box I want the checkbox to remain unchecked. Yet, if I select 5430-0100 or 5475-0100 in my drop down list in the combo box I want the checkbox to be checked.

I'm pretty sure this is doable, I am just having a difficult time in finding out how by looking on my own. If someone can, please help.

Thanks,

Marty
 
use the after update event of the combobox to update the checkbox
 
I'm not very good at VBA yet, is this code even close? I know its not right because I get errors.

Code:
Private Sub cboAccount_AfterUpdate()

Me![cboAccount] = 6100-0000 Or
Me![cboAccount] = 6200-0000 Then
Me![checkTAX] = -1
Else
Me![checkTAX] = 0
End If

End Sub
 
close try the below

Code:
If Me![cboAccount] = 6100-0000 Or _
Me![cboAccount] = 6200-0000 Then
Me![checkTAX] = -1
Else
Me![checkTAX] = 0
End If

End Sub
 
Look what happens to the code...

This is an anomaly.

Code:
Private Sub cboAccount_AfterUpdate()


If Me![cboAccount] = 6100 - 0 Or _
Me![cboAccount] = 6200 - 0 Then
Me![checkTAX] = -1
Else
Me![checkTAX] = 0
End If

End Sub

Why did it turn the 6100-0000 into 6100 - 0 ?
 
Now that I think about the data type for this field is text, correct? You need to surround the values in Quotes "value". 00000 is not a valid number so it is converted to 0.
 
actualy its Number and I've used table source / row source 'SELECT Accounts.* FROM Accounts;' expression. So I've went to table Accounts and opened it up and the primary key for 6100-0000 is 2 and 6200-0000 is 3. So I changed the code to the following....

Code:
Private Sub cboAccount_AfterUpdate()


If Me![cboAccount] = 2 Or _
Me![cboAccount] = 3 Then
Me![checkTAX] = -1
Else
Me![checkTAX] = 0
End If

End Sub

It now works fine. The only problem is that when I initially bring up a record, if it has 6100-0000 in cboAccount the checkTAX is still unchecked until I reselect 6100-0000 in cboAccount

Thats somewhat strange.

Thanks for your help sir, why is the underscore after the Or argument needed but not for the argument Then?

I don't understand
 
Last edited:
This is because when you intially bring up a record the After Update event for your combo box does not fire. You can place the same code in the Current event of the form. The current event fires when you change records.

The underscore will let you break up a long line of code into multiple lines so it is easier to read.
 

Users who are viewing this thread

Back
Top Bottom