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 / Modules / DAO / VBA / January 2006

Tip: Looking for answers? Try searching our database.

IF OR THEN, Multiple criteria VBA Function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jerad - 18 Jan 2006 15:13 GMT
I searched the forums with no avail. I cant seem to figure out how to:
function somefunction(arg1, arg2)
If arg1 = "someText" OR "SomeOtherText" AND arg2 = 1 THEN
      Run some code
else
      Run some other code
end if
Not sure how to do this, I get errors anyway I try. I get errors with even
this:

If arg1 = "someText" OR "SomeOtherText" THEN
Run some code
else
Run other code
End if
Any help would be greatly appreciated. Thank you in advance
Douglas J Steele - 18 Jan 2006 15:22 GMT
If arg1 = "someText" OR arg1 = "SomeOtherText" AND arg2 = 1 THEN

Note that you should include parentheses so it's obvious which you want:

If (arg1 = "someText" OR arg1 = "SomeOtherText") AND arg2 = 1 THEN

or

If arg1 = "someText" OR (arg1 = "SomeOtherText" AND arg2 = 1) THEN

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> I searched the forums with no avail. I cant seem to figure out how to:
> function somefunction(arg1, arg2)
[quoted text clipped - 12 lines]
> End if
> Any help would be greatly appreciated. Thank you in advance
Jerad - 18 Jan 2006 15:43 GMT
>If arg1 = "someText" OR arg1 = "SomeOtherText" AND arg2 = 1 THEN
>
>Note that you should include parentheses so it's obvious which you want:
>
>If (arg1 = "someText" OR arg1 = "SomeOtherText") AND arg2 = 1 THEN

Douglas,
Thanks for the response but I still get a "type mismatch" when using this
function in a query???
This is a simple SELECT query containing only 1 table
In my table, the field passed to Arg1 is set as "text" and the field passed
to arg2 is "number, Single"
I thought that usually "type mismatch" has to do with data type but i cant
seem to figure this out.
Thanks,
Jerad
Douglas J Steele - 18 Jan 2006 21:32 GMT
Try declaring the data types of your parameters in the function declaration:

function somefunction(arg1 As String, arg2 As Single)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> >If arg1 = "someText" OR arg1 = "SomeOtherText" AND arg2 = 1 THEN
> >
[quoted text clipped - 12 lines]
> Thanks,
> Jerad
Jerad - 18 Jan 2006 22:00 GMT
>Try declaring the data types of your parameters in the function declaration:
>
>function somefunction(arg1 As String, arg2 As Single)

Thanks for the response, I declared the variables (probably good practice
anyway,
but recieved the same erros); heres what solved the problem in case anyone
else encounters the same thing.

function somefunction(arg1 as string, arg2 as single)
If (arg1 = "someText" And arg2 = 1) OR (Arg1 = "SomeOtherText" And arg2 = 1)
Then
run some code
else
run other code
end if
I gues I had to be more specific . Works now though, thanks for help guys
JK
Douglas J. Steele - 18 Jan 2006 22:48 GMT
>>Try declaring the data types of your parameters in the function
>>declaration:
[quoted text clipped - 15 lines]
> end if
> I gues I had to be more specific . Works now though, thanks for help guys

Glad you got it working, but what you ended up with should be the same as

If (arg1 = "someText" OR arg1 = "SomeOtherText") AND arg2 = 1 THEN

I suspect you must have mistyped something if that didn't work for you.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

 
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.