By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

If statement, with multiple options

P: n/a
I currently have a button once clicked, invokes the following:

If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If

However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:

If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If

It didn't work. What am I doing wrong?

PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.

Nov 6 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Nov 6, 12:40 pm, magmike <magmi...@yahoo.comwrote:
I currently have a button once clicked, invokes the following:

If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If

However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:

If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If

It didn't work. What am I doing wrong?

PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.
I don't see anything obvious wrong with your code, except that I am
baffled as to what you are trying to do. Are you allowing the user to
select which fields appear on a form or report? Is
StockExchangeCode_Select (for example) a checkbox on the same form?
Is StockExchangeCode a textbox? Or are you trying to create some kind
of filter?

Nov 6 '07 #2

P: n/a
On Nov 6, 1:41 pm, OldPro <rrossk...@sbcglobal.netwrote:
On Nov 6, 12:40 pm, magmike <magmi...@yahoo.comwrote:


I currently have a button once clicked, invokes the following:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If
It didn't work. What am I doing wrong?
PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.

I don't see anything obvious wrong with your code, except that I am
baffled as to what you are trying to do. Are you allowing the user to
select which fields appear on a form or report? Is
StockExchangeCode_Select (for example) a checkbox on the same form?
Is StockExchangeCode a textbox? Or are you trying to create some kind
of filter?- Hide quoted text -

- Show quoted text -
the fields named select, are check boxes for the similarly named text
box. I am trying to update the values of the main form, with the
values of the subform, which come from separate sources. I don't
always want all the fields to update though. I'd like to be able to
select which fields in each instance get copied over.

Thanks!

Nov 6 '07 #3

P: n/a
magmike wrote:
I currently have a button once clicked, invokes the following:

If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If

However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:

If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If

It didn't work. What am I doing wrong?

PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.
Does it run but not work? Or do you get an error.

On your StockExchangeCode line you could move the next line onto the
same line...otherwise you might want an EndIF

If you open your code window and click on the left hand vertical bar
next to "If Address_Select = -1 Then" line, you can step through the
code when you run the process.

Nov 6 '07 #4

P: n/a
On Nov 6, 1:46 pm, Salad <o...@vinegar.comwrote:
magmike wrote:
I currently have a button once clicked, invokes the following:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If
It didn't work. What am I doing wrong?
PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.

Does it run but not work? Or do you get an error.

On your StockExchangeCode line you could move the next line onto the
same line...otherwise you might want an EndIF

If you open your code window and click on the left hand vertical bar
next to "If Address_Select = -1 Then" line, you can step through the
code when you run the process.- Hide quoted text -

- Show quoted text -
No errors. it just works one line at a time.
Once it updates one line. I have to uncheck it, the check another,
then push the button again. It's a lot of check, unchecking and button
pushing. I just want it to work once.

On the stock exchange line, I'm not sure what you mean. Could you show
me?

Nov 6 '07 #5

P: n/a
On Nov 6, 1:30 pm, magmike <magmi...@yahoo.comwrote:
On Nov 6, 1:46 pm, Salad <o...@vinegar.comwrote:


magmike wrote:
I currently have a button once clicked, invokes the following:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If
It didn't work. What am I doing wrong?
PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.
Does it run but not work? Or do you get an error.
On your StockExchangeCode line you could move the next line onto the
same line...otherwise you might want an EndIF
If you open your code window and click on the left hand vertical bar
next to "If Address_Select = -1 Then" line, you can step through the
code when you run the process.- Hide quoted text -
- Show quoted text -

No errors. it just works one line at a time.
Once it updates one line. I have to uncheck it, the check another,
then push the button again. It's a lot of check, unchecking and button
pushing. I just want it to work once.

On the stock exchange line, I'm not sure what you mean. Could you show
me?- Hide quoted text -

- Show quoted text -
Is there more code than this? If so, please post the full code so we
can truly see what's going on. I am confused because you aren't using
full references to fields.

Perhaps this would work (each IF is a single line):
If Me!Address_Select Then Forms!ProspectForm!Address = Me![Address]
If Me!City_Select Then Forms!ProspectForm!City = Me![City]
If Me!ST_Select Then Forms!ProspectForm!State = Me![ST]
If Me!ZipCode_Select Then Forms!ProspectForm!ZipCode = Me![ZipCode]
If Me!Zip4_Select Then Forms!ProspectForm!Zip4 = Me![Zip4]
If Me!MSA_Select Then Forms!ProspectForm!MSA = Me![MSA]
If Me!Phone_Select Then Forms!ProspectForm!Phone = Me![Phone]
If Me!FaxPhone_Select Then Forms!ProspectForm!Fax = Me![Fax Phone]
If Me!TickerSymbol_Select Then Forms!ProspectForm!TickerSymbol = Me!
[TICKER SYMBOL]
If Me!StockExchangeCode_Select Then Forms!ProspectForm!
StockExchangeCode = Me![STOCK EXCHANGE CODE]

Because the Select fields are CheckBoxes, they already have a True/
False value, so you don't need the =-1 part of your logical test.
This means that if your checkbox is checked, your statement is
evaluated as: If True then do this. To save yourself some typing, you
only need to use the block form of the IF statement if you're
executing more than one command. So you can have your IF all on one
line and exclude the End If part of the statement.

Block Form:
If Logical Test = True Then
Do Something Here
End If

Single-Line Form:
If Logical Test = True Then Do Something Here

HTH,
Jana

Nov 6 '07 #6

P: n/a
On Nov 6, 3:06 pm, Jana <Bauer.J...@gmail.comwrote:
On Nov 6, 1:30 pm, magmike <magmi...@yahoo.comwrote:


On Nov 6, 1:46 pm, Salad <o...@vinegar.comwrote:
magmike wrote:
I currently have a button once clicked, invokes the following:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If
It didn't work. What am I doing wrong?
PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.
Does it run but not work? Or do you get an error.
On your StockExchangeCode line you could move the next line onto the
same line...otherwise you might want an EndIF
If you open your code window and click on the left hand vertical bar
next to "If Address_Select = -1 Then" line, you can step through the
code when you run the process.- Hide quoted text -
- Show quoted text -
No errors. it just works one line at a time.
Once it updates one line. I have to uncheck it, the check another,
then push the button again. It's a lot of check, unchecking and button
pushing. I just want it to work once.
On the stock exchange line, I'm not sure what you mean. Could you show
me?- Hide quoted text -
- Show quoted text -

Is there more code than this? If so, please post the full code so we
can truly see what's going on. I am confused because you aren't using
full references to fields.

Perhaps this would work (each IF is a single line):
If Me!Address_Select Then Forms!ProspectForm!Address = Me![Address]
If Me!City_Select Then Forms!ProspectForm!City = Me![City]
If Me!ST_Select Then Forms!ProspectForm!State = Me![ST]
If Me!ZipCode_Select Then Forms!ProspectForm!ZipCode = Me![ZipCode]
If Me!Zip4_Select Then Forms!ProspectForm!Zip4 = Me![Zip4]
If Me!MSA_Select Then Forms!ProspectForm!MSA = Me![MSA]
If Me!Phone_Select Then Forms!ProspectForm!Phone = Me![Phone]
If Me!FaxPhone_Select Then Forms!ProspectForm!Fax = Me![Fax Phone]
If Me!TickerSymbol_Select Then Forms!ProspectForm!TickerSymbol = Me!
[TICKER SYMBOL]
If Me!StockExchangeCode_Select Then Forms!ProspectForm!
StockExchangeCode = Me![STOCK EXCHANGE CODE]

Because the Select fields are CheckBoxes, they already have a True/
False value, so you don't need the =-1 part of your logical test.
This means that if your checkbox is checked, your statement is
evaluated as: If True then do this. To save yourself some typing, you
only need to use the block form of the IF statement if you're
executing more than one command. So you can have your IF all on one
line and exclude the End If part of the statement.

Block Form:
If Logical Test = True Then
Do Something Here
End If

Single-Line Form:
If Logical Test = True Then Do Something Here

HTH,
Jana- Hide quoted text -

- Show quoted text -
That did, thanks! No there wasn't any other code. But for some reason,
it works perfect with the line version. Thanks a million!

I assume, that if I wanted to insert data straight into the table from
the subform, it would look like this:

If Me!Address_Select Then Table!ProspectTable!Address = Me![Address]
WHERE Table!ProspectTable!ID = Me!Forms!ProspectForm!ID

?

Nov 6 '07 #7

P: n/a
On Nov 6, 3:23 pm, magmike <magmi...@yahoo.comwrote:
On Nov 6, 3:06 pm, Jana <Bauer.J...@gmail.comwrote:


On Nov 6, 1:30 pm, magmike <magmi...@yahoo.comwrote:
On Nov 6, 1:46 pm, Salad <o...@vinegar.comwrote:
magmike wrote:
I currently have a button once clicked, invokes the following:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
However, there are 11 other fields in the subform that i'd like to be
included. However, when I did this:
If Address_Select = -1 Then
Forms!ProspectForm!Address = [Address]
End If
If City_Select = -1 Then
Forms!ProspectForm!City = [City]
End If
If ST_Select = -1 Then
Forms!ProspectForm!State = [ST]
End If
If ZipCode_Select = -1 Then
Forms!ProspectForm!ZipCode = [ZipCode]
End If
If Zip4_Select = -1 Then
Forms!ProspectForm!Zip4 = [Zip4]
End If
If MSA_Select = -1 Then
Forms!ProspectForm!MSA = [MSA]
End If
If Phone_Select = -1 Then
Forms!ProspectForm!Phone = [Phone]
End If
If FaxPhone_Select = -1 Then
Forms!ProspectForm!Fax = [Fax Phone]
End If
If TickerSymbol_Select = -1 Then
Forms!ProspectForm!TickerSymbol = [TICKER SYMBOL]
End If
If StockExchangeCode_Select = -1 Then
Forms!ProspectForm!StockExchangeCode = [STOCK EXCHANGE CODE]
End If
It didn't work. What am I doing wrong?
PS - I should say, as long as only one of them is checked, it will
work. But if I check all, then hit my button, it won't do it.
Does it run but not work? Or do you get an error.
On your StockExchangeCode line you could move the next line onto the
same line...otherwise you might want an EndIF
If you open your code window and click on the left hand vertical bar
next to "If Address_Select = -1 Then" line, you can step through the
code when you run the process.- Hide quoted text -
- Show quoted text -
No errors. it just works one line at a time.
Once it updates one line. I have to uncheck it, the check another,
then push the button again. It's a lot of check, unchecking and button
pushing. I just want it to work once.
On the stock exchange line, I'm not sure what you mean. Could you show
me?- Hide quoted text -
- Show quoted text -
Is there more code than this? If so, please post the full code so we
can truly see what's going on. I am confused because you aren't using
full references to fields.
Perhaps this would work (each IF is a single line):
If Me!Address_Select Then Forms!ProspectForm!Address = Me![Address]
If Me!City_Select Then Forms!ProspectForm!City = Me![City]
If Me!ST_Select Then Forms!ProspectForm!State = Me![ST]
If Me!ZipCode_Select Then Forms!ProspectForm!ZipCode = Me![ZipCode]
If Me!Zip4_Select Then Forms!ProspectForm!Zip4 = Me![Zip4]
If Me!MSA_Select Then Forms!ProspectForm!MSA = Me![MSA]
If Me!Phone_Select Then Forms!ProspectForm!Phone = Me![Phone]
If Me!FaxPhone_Select Then Forms!ProspectForm!Fax = Me![Fax Phone]
If Me!TickerSymbol_Select Then Forms!ProspectForm!TickerSymbol = Me!
[TICKER SYMBOL]
If Me!StockExchangeCode_Select Then Forms!ProspectForm!
StockExchangeCode = Me![STOCK EXCHANGE CODE]
Because the Select fields are CheckBoxes, they already have a True/
False value, so you don't need the =-1 part of your logical test.
This means that if your checkbox is checked, your statement is
evaluated as: If True then do this. To save yourself some typing, you
only need to use the block form of the IF statement if you're
executing more than one command. So you can have your IF all on one
line and exclude the End If part of the statement.
Block Form:
If Logical Test = True Then
Do Something Here
End If
Single-Line Form:
If Logical Test = True Then Do Something Here
HTH,
Jana- Hide quoted text -
- Show quoted text -

That did, thanks! No there wasn't any other code. But for some reason,
it works perfect with the line version. Thanks a million!

I assume, that if I wanted to insert data straight into the table from
the subform, it would look like this:

If Me!Address_Select Then Table!ProspectTable!Address = Me![Address]
WHERE Table!ProspectTable!ID = Me!Forms!ProspectForm!ID

?- Hide quoted text -

- Show quoted text -
Mike:
The Me! additions are probably what did it, as that references the
current form you are on. I have never updated a table like that, so
I'm not sure if that will work...make a backup copy, and give it a
shot!

Glad I could help,
Jana

Nov 6 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.