Using an IF ELSE AND command

  • Thread starter Thread starter Kevin_melb via AccessMonster.com
  • Start date Start date
K

Kevin_melb via AccessMonster.com

My next problem that I need to address is using a “IF command.

Basically I want the following procedure

IF [companyname] = [1234] then [laborcost] = [hourlyrate] and [laborsell] =
[hourlyratre]
Or [jobnumberID] = [10049] then [laborcost] = [nilrate] and [laborsell] =
[nilrate]
Else [laborcost] = [costrate] and [laborsell] = [chargerate]

I am not sure how to do this when I click on “update on Exitâ€

Many Thanks

Kevin
 
My next problem that I need to address is using a “IF command.

Basically I want the following procedure

IF [companyname] = [1234] then [laborcost] = [hourlyrate] and [laborsell] =
[hourlyratre]
Or [jobnumberID] = [10049] then [laborcost] = [nilrate] and [laborsell] =
[nilrate]
Else [laborcost] = [costrate] and [laborsell] = [chargerate]

I am not sure how to do this when I click on “update on Exit”

Many Thanks

Kevin

I have NO idea what you're talking about, Kevin.

If you're trying to do this in the Click event of a command button, your
syntax is wrong. The word AND is a grammatical conjunction in English but it's
a logical operator in VBA. The correct syntax to do what you describe would be

Private Sub Update_On_Exit_Click()
IF [companyname] = [1234] then
[laborcost] = [hourlyrate]
[laborsell] = [hourlyratre]
ElseIf [jobnumberID] = [10049] then
[laborcost] = [nilrate]
[laborsell] = [nilrate]
Else
[laborcost] = [costrate]
[laborsell] = [chargerate]
End If
End Sub

However, hardcoding company names and job number ID's in your VBA code REALLY
sounds like flawed design! Just what are you trying to accomplish!? What does
this Click event do which a properly bound form doesn't? What would you want
to happen if CompanyName was equal to the value in the control named [1234],
and the JobnumberID was equal to whatever value is in the control named
[10049]? Or do you intend those to be literal string values, in which case you
should use " as a delimiter instead of brackets?


John W. Vinson [MVP]
 
Sorry John, my bad explaination. What i am doing is time sheets for employees
to charge there time against a job. The brackets are just my way of explaning
that the fileds are in a table that i use.
The reason that i use the customer name is to change the charge rate. Say we
have a warrenty job to do, the cost and sell rate have to be the same and if
i have peron on leave without pay then the cost and sell rate are zero. If
these 2 requiremtns are not made then i just allow the normal cost and chareg
rate to be applied to the job.

Sorry not putting it clear enough. I see the basic layout of the code and i
think i can work that so i achieve what i want to achieve.

Many thanks again

Kevin

P.S i probalbly will ask more silly questions soon lol
My next problem that I need to address is using a “IF command.
[quoted text clipped - 11 lines]

I have NO idea what you're talking about, Kevin.

If you're trying to do this in the Click event of a command button, your
syntax is wrong. The word AND is a grammatical conjunction in English but it's
a logical operator in VBA. The correct syntax to do what you describe would be

Private Sub Update_On_Exit_Click()
IF [companyname] = [1234] then
[laborcost] = [hourlyrate]
[laborsell] = [hourlyratre]
ElseIf [jobnumberID] = [10049] then
[laborcost] = [nilrate]
[laborsell] = [nilrate]
Else
[laborcost] = [costrate]
[laborsell] = [chargerate]
End If
End Sub

However, hardcoding company names and job number ID's in your VBA code REALLY
sounds like flawed design! Just what are you trying to accomplish!? What does
this Click event do which a properly bound form doesn't? What would you want
to happen if CompanyName was equal to the value in the control named [1234],
and the JobnumberID was equal to whatever value is in the control named
[10049]? Or do you intend those to be literal string values, in which case you
should use " as a delimiter instead of brackets?

John W. Vinson [MVP]
 
Sorry John, my bad explaination. What i am doing is time sheets for employees
to charge there time against a job. The brackets are just my way of explaning
that the fileds are in a table that i use.
The reason that i use the customer name is to change the charge rate. Say we
have a warrenty job to do, the cost and sell rate have to be the same and if
i have peron on leave without pay then the cost and sell rate are zero. If
these 2 requiremtns are not made then i just allow the normal cost and chareg
rate to be applied to the job.

Then I'd suggest that you NOT do this in code. Instead, consider storing each
customer's charge rate in the Customers table, and use it in your query; and
have a job-type field, with perhaps an IIF([JobType] = "Warrenty", 0,
[Customers].[Rate]) expression in a query to select the rate. It's not
necessary to use VBA code to do this, and it's certainly not necessary or
appropriate to hardcode table values in the code!

John W. Vinson [MVP]
 
Ok Thanks Joh I will head down that path and see how i go
Kevin
Sorry John, my bad explaination. What i am doing is time sheets for employees
to charge there time against a job. The brackets are just my way of explaning
[quoted text clipped - 4 lines]
these 2 requiremtns are not made then i just allow the normal cost and chareg
rate to be applied to the job.

Then I'd suggest that you NOT do this in code. Instead, consider storing each
customer's charge rate in the Customers table, and use it in your query; and
have a job-type field, with perhaps an IIF([JobType] = "Warrenty", 0,
[Customers].[Rate]) expression in a query to select the rate. It's not
necessary to use VBA code to do this, and it's certainly not necessary or
appropriate to hardcode table values in the code!

John W. Vinson [MVP]
 

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

Back
Top