Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / November 2007

Tip: Looking for answers? Try searching our database.

If statement, with multiple options

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
magmike - 06 Nov 2007 18:40 GMT
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.
OldPro - 06 Nov 2007 19:41 GMT
> I currently have a button once clicked, invokes the following:
>
[quoted text clipped - 40 lines]
> 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?
magmike - 06 Nov 2007 19:45 GMT
> > I currently have a button once clicked, invokes the following:
>
[quoted text clipped - 49 lines]
>
> - 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!
Salad - 06 Nov 2007 19:46 GMT
> I currently have a button once clicked, invokes the following:
>
[quoted text clipped - 40 lines]
> 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.
magmike - 06 Nov 2007 20:30 GMT
> > I currently have a button once clicked, invokes the following:
>
[quoted text clipped - 51 lines]
>
> - 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?
Jana - 06 Nov 2007 21:06 GMT
> > > I currently have a button once clicked, invokes the following:
>
[quoted text clipped - 61 lines]
>
> - 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
magmike - 06 Nov 2007 22:23 GMT
> > > > I currently have a button once clicked, invokes the following:
>
[quoted text clipped - 100 lines]
>
> - 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

?
Jana - 06 Nov 2007 23:43 GMT
> > > > > I currently have a button once clicked, invokes the following:
>
[quoted text clipped - 113 lines]
>
> - 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.