YES/NO FIELD IN COMBOBOX

B

BobbyDazzler

tblCustomer

custid PK autonumber
custname text
custcode text
custacct yes/no

used in frminvoice as combobox using all 4 fields (custid hidden)

example data in combobox

A D Plumbers | AD0001 | -1
Smith, Andrew | SM0001 | 0

column(3) either shows -1 for true or 0 for false

This field indicates whether the customer is an account holder or not,
if they are then txtsaletype should read "CREDIT SALE" and if they
aren't it should read "CASH SALE"


Once a customer is selected from the drop down list I have this code
running in the afterupdate event:-

If Me!cboSelect.Column(3) = -1 Then
Me!chkCustomerAcctHeld = -1
Else
Me!chkCustomerAcctHeld = 0
End If

If Me!chkCustomerAcctHeld = -1 Then
txtsaletype = "CREDIT SALE"
Else
txtsaletype = "CASH SALE"
End If


It doesn't work! Where am I going wrong?

Thanks

David
 
A

Armen Stein

Once a customer is selected from the drop down list I have this code
running in the afterupdate event:-

If Me!cboSelect.Column(3) = -1 Then
Me!chkCustomerAcctHeld = -1
Else
Me!chkCustomerAcctHeld = 0
End If

If Me!chkCustomerAcctHeld = -1 Then
txtsaletype = "CREDIT SALE"
Else
txtsaletype = "CASH SALE"
End If


It doesn't work! Where am I going wrong?

What doesn't work about it?

Why don't you just set the ControlSource of the txtsaletype control
to:

=IIF(Me!cboSelect.Column(3) = 0, "CASH SALE", "CREDIT SALE")

Then you can remove all your after update code.

PS - It is not advisable to use a real email address in a public
newsgroup, as spammers can harvest addresses from here.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
B

BobbyDazzler

What doesn't work about it?

It doesn't chamge from Yes to No and No to Yes as it should
Why don't you just set the ControlSource of the txtsaletype control
to:

=IIF(Me!cboSelect.Column(3) = 0, "CASH SALE", "CREDIT SALE")

Then you can remove all your after update code.


This isn't the only place that the info can be set from. The form is
used for new invoices, view invoices, view uninvoiced and view upaid
invoice
all with different recordsources!

So needs to be this way.
PS - It is not advisable to use a real email address in a public
newsgroup, as spammers can harvest addresses from here.

It's ok, this is my spam email address!
 
B

Bob Quintal

:
tblCustomer

custid PK autonumber
custname text
custcode text
custacct yes/no

used in frminvoice as combobox using all 4 fields (custid hidden)

example data in combobox

A D Plumbers | AD0001 | -1
Smith, Andrew | SM0001 | 0

column(3) either shows -1 for true or 0 for false

This field indicates whether the customer is an account holder or
not, if they are then txtsaletype should read "CREDIT SALE" and if
they aren't it should read "CASH SALE"


Once a customer is selected from the drop down list I have this
code running in the afterupdate event:-

If Me!cboSelect.Column(3) = -1 Then
Me!chkCustomerAcctHeld = -1
Else
Me!chkCustomerAcctHeld = 0
End If

If Me!chkCustomerAcctHeld = -1 Then
txtsaletype = "CREDIT SALE"
Else
txtsaletype = "CASH SALE"
End If


It doesn't work! Where am I going wrong?

Thanks

David
Where are you going wrong? do you want the long list or the short
one?
the short list is
1) .Column(n) is ZERO-based, so your columns are 0,1,2 not 1,2,3
2) you are using the literal -1 and 0 instead of True and False
3) what is txtsaletype? the name implies a textbox, which should be
prefixed with Me! or Form!Name!
4) you are using multiple if-else blocks where only 1 is needed.


If Me!cboSelect.Column(2) Then
Me!chkCustomerAcctHeld = True
Mew!txtsaletype = "CREDIT SALE"
Else
Me!chkCustomerAcctHeld = False
Mew!txtsaletype = "CASH SALE"
End If
 
B

BobbyDazzler

Where are you going wrong? do you want the long  list or the short

Give me the long one!
the short list is
1) .Column(n) is ZERO-based, so your columns are 0,1,2 not 1,2,3

Yeah, I know, there are four columns! 0,1,2,3
2) you are using the literal -1 and 0 instead of True and False

ok, have changed
3) what is txtsaletype? the name implies a textbox, which should be
prefixed with Me! or Form!Name!

your right, it was in my app I retyped instead of copying and pasting
4) you are using multiple if-else blocks where only 1 is needed.

If Me!cboSelect.Column(2) Then

is there somthing missing on this line?
   Me!chkCustomerAcctHeld = True
   Mew!txtsaletype = "CREDIT SALE"

is this a typo?
Else
   Me!chkCustomerAcctHeld = False
   Mew!txtsaletype = "CASH SALE"
End If
Tried with Me! and with True/False and without multiple ifs and still
doesn't work!
 
B

BobbyDazzler

If Me!cboSelect.Column(3)

should have been

If Me!cboSelectCustomer.Column(3)


What a muppet! Sorry folks and thanks for the help!
 
B

Bob Quintal

Give me the long one!


Yeah, I know, there are four columns! 0,1,2,3


ok, have changed


your right, it was in my app I retyped instead of copying and pasting

is there somthing missing on this line?

no actually, that is working code
Visual basic always reduces an IF statement to If Not False then
False is a constant which is 0. Any non 0 value is therefore True
Me!cboSelect.Column(2) = True gets evaluated and reduced to
Not False = Not False which is further evaluated to Not False.
but Me!cboSelect.Column(2) is already Not False, so writing it as I
have above saves 3 evaluations
is this a typo?

yes, sorry. fingers faster thgan brain.
Tried with Me! and with True/False and without multiple ifs and still
doesn't work!
From your reply to yourself, I think you should go into the Visual
Basic Menu -> Tools -> Options -> Editor and check Require Variable
Declaration. That probably would have given you an error at compile
time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top