help with select case (1 Viewer)

peterod

Registered User.
Local time
Today, 11:27
Joined
Jan 13, 2011
Messages
31
this is hopefully straight forward for you guys.

im struggling to get to grips with the select case statement and would really appreciate if

i want to have a field that performs a different calculation for each record



heres what i thought it should look like,

Select Case [quantity] (is this the field that i want the result to appear?)
Case 1
[id]!"1" [fielda] * [fieldb]
Case 2
[id]!"2" [fielda] * [fieldb] / [[fieldc]
Case Else
Wscript.Echo "calc still to be set up for an id"
End Select

please help
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:27
Joined
Aug 30, 2003
Messages
36,124
It is not where you want the result, It's what you're testing. In words, what you have above is "if the value in [quantity] is 1, do this, if it's 2, do that, otherwise do this other thing". Not sure what you're trying to accomplish with those cases.
 

peterod

Registered User.
Local time
Today, 11:27
Joined
Jan 13, 2011
Messages
31
with that in mind, if I have the below statment as the data source in my quantity field then, it should do the required calc based on the value of the id field. please help.

I'm really just trying to have a quantity field which will carry out a different pre-set calc for every record in the database.

Can you tell me if you think this would work then

Select Case [ID] (should then check the value of the id field, and if it = 1 then?)
Case 1
[fielda] * [fieldb]
Case 2
[fielda] * [fieldb] / [[fieldc]
Case Else
Echo "calc still to be set up for an id"
End Select

I really have just started using vba this week, and if I can get this to work I think it will be as far as I need to go with it. (for now anyway)
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:27
Joined
Aug 30, 2003
Messages
36,124
Are you using VB or VBA (in Access, Excel, etc)? In VBA I'd expect:

Me.Quantity = Me.[fielda] * Me.[fieldb]

You might do it in the after update event of the ID control, or elsewhere depending on your specifics.
 

Guus2005

AWF VIP
Local time
Today, 20:27
Joined
Jun 26, 2007
Messages
2,641
You might want to consider using Switch or Choose.

HTH:D
 

Users who are viewing this thread

Top Bottom