Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2005, 10:05 AM
Authorized User
 
Join Date: Dec 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default If statements in a function?

Hi

I'm developing the purchasing database. I am working on processing input details. The opening form is taken from an employee details table and has the standard fields such as Employee number, first name , second name etc. I also have checkboxes representing the benefits an employee can have ie Car, Carpark, Phone and Fuel. I thought that depending on the combination of tickboxes ticked, unticked, I could hold a value in a variable (eg x) that will denote that combination for each employee. I could then use this value to determine what queries need to be ran when viewing details for the employee. The function I have coded in order to calculate x is rejected because of arguments eg

Function getx(vcar As Variant, vphone As Variant, vCarpark As Integer, vFuel As Variant) As Integer

If vcar = -1 And vphone = 0 And vCarpark = 0 And vFuel = 0 Then
    X = 1
Else
    X = 0
End If

etc


Is it possible to use a function with if statements?


Cheers
Tony
__________________
Cheers
Tony
 
Old February 17th, 2005, 12:32 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can use any flow control you want in a function. The function only takes variables and works out a value to return.

It seems to me that you are going to have 16 different combinations of variables you will need to check. That could get dicey.

Perhaps on your form you want to hide the CarPark check box unless the Car check box was checked, and maybe the same for the Fuel check box?

Then you can nest your If Thens like this:
'==========
'This script returns 0
stCar = -1
stCarPark = 0
stX = 0

If stCar = -1 Then
  If stCarPark = -1 Then
    stX = 1
  End If
End If

WScript.Echo stX
'==========

And...

'==========
'This script returns 1
stCar = -1
stCarPark = -1
stX = 0

If stCar = -1 Then
  If stCarPark = -1 Then
    stX = 1
  End If
End If

WScript.Echo stX
'==========

And...

'==========
'This script returns 0
stCar = 0
stCarPark = 0
stX = 0

If stCar = -1 Then
  If stCarPark = -1 Then
    stX = 1
  End If
End If

WScript.Echo stX
'==========

You get the idea.

HTH



mmcdonal
 
Old February 21st, 2005, 11:42 AM
Authorized User
 
Join Date: Dec 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cheers

Cheers
Tony





Similar Threads
Thread Thread Starter Forum Replies Last Post
IF Statements with OID Navy1991_1 XSLT 4 June 3rd, 2008 12:08 PM
if statements brainchild Javascript 2 March 1st, 2007 06:08 AM
Case Statements cfriedberg SQL Server 2000 1 September 7th, 2005 08:46 PM
IF ELSE statements gmpurple Classic ASP Databases 4 November 15th, 2004 04:30 PM
If, else if statements Joel JSP Basics 0 March 18th, 2004 06:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.