By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,781 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,781 IT Pros & Developers. It's quick & easy.

Access 2002 Conditional Caption

P: n/a
I have a form that returns 100 items. All of the items have have a
different value in their Category field.

EXAMPLE:
----------------
A
B
C

How can I change the value of the caption in the field label on the
form based on the category? I attempted a series of Case statements
but it didn't seem to work when values of mixed categories were
returned.

Select Case PriceCat
Case "A"
MsgBox ([tblProduct.PriceTyp])
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource =
"PriceTypeA"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource =
"PriceTypeB"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource =
"PriceTypeC"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "A"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "B"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "C"
Case Else
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource = "1"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource = "2"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource = "3"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "1"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "2"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "3"
End Select
Jan 16 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
What you could try is this,

in your form's current event, you could implement a simple 'If'
statement

i.e.

if pricecat = "A" Then
yourlabel.caption = "The category is A"
elseif pricecat = "B" Then
yourlabel.caption = "The category is B"
elseif pricecat = "C" Then
yourlabel.caption = "The category is C"
else
yourlabel.caption = "Category not A,B, or C"
End if

I think that should work.
Jan 16 '08 #2

P: n/a
Mixed Catagories? It sounds like your main form is set to 'Continuous
View'. I expect that you would only have one catagory per Record.
Your code will only work in you Current Record. So the labels should
change when you go to the next record.

Dominic

<dk****@gmail.comwrote in message
news:02**********************************@c23g2000 hsa.googlegroups.com...
>I have a form that returns 100 items. All of the items have have a
different value in their Category field.

EXAMPLE:
----------------
A
B
C

How can I change the value of the caption in the field label on the
form based on the category? I attempted a series of Case statements
but it didn't seem to work when values of mixed categories were
returned.

Select Case PriceCat
Case "A"
MsgBox ([tblProduct.PriceTyp])
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource =
"PriceTypeA"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource =
"PriceTypeB"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource =
"PriceTypeC"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "A"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "B"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "C"
Case Else
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource = "1"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource = "2"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource = "3"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "1"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "2"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "3"
End Select

Jan 16 '08 #3

P: n/a
On Jan 16, 2:02 pm, "Dominic Vella" <dominic.ve...@optusnet.com.au>
wrote:
Mixed Catagories? It sounds like your main form is set to 'Continuous
View'. I expect that you would only have one catagory per Record.
Your code will only work in you Current Record. So the labels should
change when you go to the next record.

Dominic

<dko...@gmail.comwrote in message

news:02**********************************@c23g2000 hsa.googlegroups.com...
I have a form that returns 100 items. All of the items have have a
different value in their Category field.
EXAMPLE:
----------------
A
B
C
How can I change the value of the caption in the field label on the
form based on the category? I attempted a series of Case statements
but it didn't seem to work when values of mixed categories were
returned.
Select Case PriceCat
Case "A"
MsgBox ([tblProduct.PriceTyp])
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource =
"PriceTypeA"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource =
"PriceTypeB"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource =
"PriceTypeC"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "A"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "B"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "C"
Case Else
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource = "1"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource = "2"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource = "3"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "1"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "2"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "3"
End Select
The form is set to continuous because I am returning more than one
record. I am returning the records for view only.
Jan 17 '08 #4

P: n/a
I'd consider using a list box with the results, and let the user select the
result they would like more detail from, then you can use the 'Single View'.

In any case, make sure your code is placed in your Form_Current event.

Dominic

<dk****@gmail.comwrote in message
news:01**********************************@v46g2000 hsv.googlegroups.com...
On Jan 16, 2:02 pm, "Dominic Vella" <dominic.ve...@optusnet.com.au>
wrote:
>Mixed Catagories? It sounds like your main form is set to 'Continuous
View'. I expect that you would only have one catagory per Record.
Your code will only work in you Current Record. So the labels should
change when you go to the next record.

Dominic

<dko...@gmail.comwrote in message

news:02**********************************@c23g200 0hsa.googlegroups.com...
>I have a form that returns 100 items. All of the items have have a
different value in their Category field.
EXAMPLE:
----------------
A
B
C
How can I change the value of the caption in the field label on the
form based on the category? I attempted a series of Case statements
but it didn't seem to work when values of mixed categories were
returned.
Select Case PriceCat
Case "A"
MsgBox ([tblProduct.PriceTyp])
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource =
"PriceTypeA"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource =
"PriceTypeB"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource =
"PriceTypeC"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "A"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "B"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "C"
Case Else
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource = "1"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource = "2"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource = "3"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "1"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "2"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "3"
End Select

The form is set to continuous because I am returning more than one
record. I am returning the records for view only.

Jan 17 '08 #5

P: n/a
On Jan 16, 7:19 pm, "Dominic Vella" <dominic.ve...@optusnet.com.au>
wrote:
I'd consider using a list box with the results, and let the user select the
result they would like more detail from, then you can use the 'Single View'.

In any case, make sure your code is placed in your Form_Current event.

Dominic

<dko...@gmail.comwrote in message

news:01**********************************@v46g2000 hsv.googlegroups.com...
On Jan 16, 2:02 pm, "Dominic Vella" <dominic.ve...@optusnet.com.au>
wrote:
Mixed Catagories? It sounds like your main form is set to 'Continuous
View'. I expect that you would only have one catagory per Record.
Your code will only work in you Current Record. So the labels should
change when you go to the next record.
Dominic
<dko...@gmail.comwrote in message
>news:02**********************************@c23g200 0hsa.googlegroups.com...
I have a form that returns 100 items. All of the items have have a
different value in their Category field.
EXAMPLE:
----------------
A
B
C
How can I change the value of the caption in the field label on the
form based on the category? I attempted a series of Case statements
but it didn't seem to work when values of mixed categories were
returned.
Select Case PriceCat
Case "A"
MsgBox ([tblProduct.PriceTyp])
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource =
"PriceTypeA"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource =
"PriceTypeB"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource =
"PriceTypeC"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "A"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "B"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "C"
Case Else
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource = "1"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource = "2"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource = "3"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "1"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "2"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "3"
End Select
The form is set to continuous because I am returning more than one
record. I am returning the records for view only.
Listbox won't work...that is how I had the form initially...but the
user group would like to see it all at once...
Jan 17 '08 #6

P: n/a
On Jan 16, 1:56 pm, Brian <Brian.Kib...@gmail.comwrote:
What you could try is this,

in your form's current event, you could implement a simple 'If'
statement

i.e.

if pricecat = "A" Then
yourlabel.caption = "The category is A"
elseif pricecat = "B" Then
yourlabel.caption = "The category is B"
elseif pricecat = "C" Then
yourlabel.caption = "The category is C"
else
yourlabel.caption = "Category not A,B, or C"
End if

I think that should work.
Didn't seem to work. All the category labels were = "Category not
A,B, or C". All the items in the return were from category A, B, C
with the exception of the first item in the resultset that was not.
When I remove that item, the first item in the result set is from
Category B, and all the labels are then = "Category B".
Jan 18 '08 #7

P: n/a
On Thu, 17 Jan 2008 08:27:06 -0800 (PST), "dk****@gmail.com" <dk****@gmail.com>
wrote:
>On Jan 16, 7:19 pm, "Dominic Vella" <dominic.ve...@optusnet.com.au>
wrote:
>I'd consider using a list box with the results, and let the user select the
result they would like more detail from, then you can use the 'Single View'.

In any case, make sure your code is placed in your Form_Current event.

Dominic

<dko...@gmail.comwrote in message

news:01**********************************@v46g200 0hsv.googlegroups.com...
On Jan 16, 2:02 pm, "Dominic Vella" <dominic.ve...@optusnet.com.au>
wrote:
Mixed Catagories? It sounds like your main form is set to 'Continuous
View'. I expect that you would only have one catagory per Record.
Your code will only work in you Current Record. So the labels should
change when you go to the next record.
>Dominic
><dko...@gmail.comwrote in message
>>news:02**********************************@c23g20 00hsa.googlegroups.com...
>I have a form that returns 100 items. All of the items have have a
different value in their Category field.
EXAMPLE:
----------------
A
B
C
How can I change the value of the caption in the field label on the
form based on the category? I attempted a series of Case statements
but it didn't seem to work when values of mixed categories were
returned.
Select Case PriceCat
Case "A"
MsgBox ([tblProduct.PriceTyp])
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource =
"PriceTypeA"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource =
"PriceTypeB"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource =
"PriceTypeC"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "A"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "B"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "C"
Case Else
Me![frmSubSearch].Form.prdPrice1Gl.ControlSource = "1"
Me![frmSubSearch].Form.prdPrice5Gl.ControlSource = "2"
Me![frmSubSearch].Form.prdPrice5GlCF.ControlSource = "3"
Me![frmSubSearch].Form.lblItemSubPrice1.Caption = "1"
Me![frmSubSearch].Form.lblItemSubPrice5.Caption = "2"
Me![frmSubSearch].Form.lblItemSubPrice5CF.Caption = "3"
End Select
The form is set to continuous because I am returning more than one
record. I am returning the records for view only.

Listbox won't work...that is how I had the form initially...but the
user group would like to see it all at once...
Replace the label with a text box (disabled and locked).
Either create a calculated field in the recordsource of the form that returns
the correct caption for the record and bind the textbox to this field.

OR

Create a function that returns the required caption based on parameters past to
it and bind the textbox to this function. This will be significantly slower than
the first option and may result in a staggered screen update.

If you use a label whatever caption you set will apply to every record in the
continuous form. Using a textbox allows each record to be evaluated and
displayed individually.
Wayne Gillespie
Gosford NSW Australia
Jan 18 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.