A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Case statement Problem



 
 
Thread Tools Display Modes
  #21  
Old July 5th, 2008, 10:33 AM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Case statement Problem not resolved

The problem would appear to be that the value in Me.Combo28.Column(1) is not
what you're expecting it to be. In other words, whatever value is there
never starts with either a B or a C.

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


"tony Jacobs" wrote in message
...
Damon;
I tried your code and I added 3 message boxes at the end of the code to
see
the value of the stDocName and it is always the report name in the Case
else
statement.

It seems that we are close, but the conditional reports are not being
picked
up .


"Damon Heron" wrote in message
...
Before the Select Case statement, put:

debug.print Left(Me.Combo28.column(1) & "",1)

if the correct answer appears in the immediate window, then you might
try:
dim myrpt as variant
myrpt= Left(Me.Combo28.Column(1) & "",1)
Select Case myrpt
Case "B"
...........
Case "C"
etc.

There is no way the correct report name would not be assigned to
stDocName
in this case.

Damon



"tony Jacobs" wrote in message
...
No Damon;

The problem is that the same report opens in all cases. Which means
that
the
case statement is not picking up the value of the combo box.
The open report works perfectly and it tells me which records in the

list
box it is about to print.

Now what I am trying to do is limit the list box to all items that
start
with a C, then print the C report

Limit items to all that start with a B then print all items that Start
with
a B , then Print the B report (I called it report2 for example).

The "ProductID IN " & strSelected statement.is flawless. I worked it

out.

Happy 4th of July. Proud to be an American.

"Damon Heron" wrote in message
. ..
I would suggest you put a breakpoint at the beginning of your case
stmt
and
step thru the code, checking values-- if the code picks the correct
report
name, then the problem is in your DoCmd.OpenReport stDocName,
acViewPreview,
, "ProductID IN " & strSelected statement.

Damon


"tony Jacobs" wrote in message
...
Doug;

No luck. No Errors but no results.

Thanks for your time


"Douglas J. Steele" wrote in
message
...
Given you were trying to use Column(1) in your first example, try

Select Case Left(Me.Combo28.Column(1) & "", 1)

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


"tony Jacobs" wrote in message
...
Sorry John; I did not work ! Any other ideas?


"John Spencer" wrote in message
...
Select Case Left(Me.Combo28 & "",1)

Case "B"
stDocName = "Productsreport1"

Case "C"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select

DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN "

&
strSelected


'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


strive4peace wrote:
hi Tony

"Me![Combo28].column(1) = Like'B*'"
-- left(Me![Combo28].column(1),1) = "B"

"Me![Combo28].column(1) = 'Like'C*''"
-- left(Me![Combo28].column(1),1) = "C"


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




tony Jacobs wrote:
I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value of

the
combo
box,
and based on that it will select which report to print, but I
can
not
get it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN

"
&
strSelected


Thanks in advance


















  #22  
Old July 5th, 2008, 11:27 AM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
John Spencer
external usenet poster
 
Posts: 2,364
Default Case statement Problem few more tries

Crystal,

I believe you can use Like in VBA. I do so on occasion.

Perhaps you meant that you can't use Like in Case statements - which I
believe is correct.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


strive4peace wrote:
Hi Tony,

this is not right:
Case "Like'B*'"

firstly, you would need a space after the word Like; second, you would
not include Like in the quotes (it is, essentially, the operator) -- and
Access does not interpret what is in quotes as part of code syntax ...
but anyway, you cannot use 'Like' in VBA code (works fine in SQL -- ie:
queries). If you want to test the first character for "B", you need to
do what Doug suggested:

Select Case Left(Me.Combo28.Column(1) & "", 1)
Case "B"



Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




tony Jacobs wrote:
I tried the code without the left function, and my debugging message box
returns what is actually in the combobox column(1) which is any of the
below
criteria. here is the code:
.................................................. ..........................

.................................................. ..........................

.............

Debug.Print Me.Combo28.Column(1)

' Select Case Left(Me.Combo28 & "", 1)
' Select Case Left(Me![Combo28].Column(1), 1)

Dim myrpt As Variant
myrpt = Me.Combo28.Column(1)

Select Case myrpt

Case "Like'B*'"

stDocName = "Productsreport1"

Case "Like'C*'"

' Case Left(Me![Combo28].Column(1), 1) = "C"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select

MsgBox ("The ComboBox Value is " & Me.Combo28.Column(1)),
vbInformation,
" OOps "
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN " &
strSelected

EndIT:

End Sub
.................................................. ..........................

.................................................. ..........................

...................

the immediate window returns the following or has returned the
following ( I
figured out how to work it now)
(below using the left statement)
L
L
L

using only the (Me.Combo28.Column(1))

Like 'C*'
Like 'C*'
Like 'C*'
Like 'P*'
Like 'B*'
.................................................. ..........................

.................................................. ..........................

....................

Still the report printed is the last one which is in the case else
condition.








"tony Jacobs" wrote in message
...
Okay a quick update: I put a message box that printed the value of the

Combo
box, and the left statement returns the letter "L" only

that's why the report selection is bypassed to the Case Else Statement .

Please note that the coulmn(1) in the combobox is as follows

Column(1) is:
Like 'C*'
Like 'P*'
Like 'B*'
Like '*'
Like 'Z*'
Like"[b]*"
Like "[BC]*"


I am thinking of trying the combobox without the Left function.


"tony Jacobs" wrote in message
...
Compile Error
Expected Expression if I put ? Debug.Print Left(Me.Combo28.Column(1)

&
"", 1) in thr immediate window

Also I get an error that the Value of the Combo Box is not set yet.or

not
calculated. I used to be able to use the immediate window very
successfully.
Please tell me if I am doing something wrong.

Thanks



"Damon Heron" wrote in message
...
Before the Select Case statement, put:

debug.print Left(Me.Combo28.column(1) & "",1)

if the correct answer appears in the immediate window, then you might
try:
dim myrpt as variant
myrpt= Left(Me.Combo28.Column(1) & "",1)
Select Case myrpt
Case "B"
...........
Case "C"
etc.

There is no way the correct report name would not be assigned to
stDocName
in this case.

Damon



"tony Jacobs" wrote in message
...
No Damon;

The problem is that the same report opens in all cases. Which means
that
the
case statement is not picking up the value of the combo box.
The open report works perfectly and it tells me which records in the
list
box it is about to print.

Now what I am trying to do is limit the list box to all items that
start
with a C, then print the C report

Limit items to all that start with a B then print all items that

Start
with
a B , then Print the B report (I called it report2 for example).

The "ProductID IN " & strSelected statement.is flawless. I worked it
out.
Happy 4th of July. Proud to be an American.

"Damon Heron" wrote in message
. ..
I would suggest you put a breakpoint at the beginning of your case
stmt
and
step thru the code, checking values-- if the code picks the correct
report
name, then the problem is in your DoCmd.OpenReport stDocName,
acViewPreview,
, "ProductID IN " & strSelected statement.

Damon


"tony Jacobs" wrote in message
...
Doug;

No luck. No Errors but no results.

Thanks for your time


"Douglas J. Steele" wrote in
message
...
Given you were trying to use Column(1) in your first example,

try
Select Case Left(Me.Combo28.Column(1) & "", 1)

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


"tony Jacobs" wrote in message
...
Sorry John; I did not work ! Any other ideas?


"John Spencer" wrote in message
...
Select Case Left(Me.Combo28 & "",1)

Case "B"
stDocName = "Productsreport1"

Case "C"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select

DoCmd.OpenReport stDocName, acViewPreview, , "ProductID

IN
"
&
strSelected


'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


strive4peace wrote:
hi Tony

"Me![Combo28].column(1) = Like'B*'"
-- left(Me![Combo28].column(1),1) = "B"

"Me![Combo28].column(1) = 'Like'C*''"
-- left(Me![Combo28].column(1),1) = "C"


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




tony Jacobs wrote:
I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value

of
the
combo
box,
and based on that it will select which report to print,

but
I
can
not
get it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID
IN
"
&
strSelected


Thanks in advance












  #23  
Old July 5th, 2008, 02:33 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
tony Jacobs
external usenet poster
 
Posts: 50
Default Case statement Problem few more tries

Crystal;

IF I do not use the " access complains about it as an error.


"strive4peace" wrote in message
...
Hi Tony,

this is not right:
Case "Like'B*'"

firstly, you would need a space after the word Like; second, you would
not include Like in the quotes (it is, essentially, the operator) -- and
Access does not interpret what is in quotes as part of code syntax ...
but anyway, you cannot use 'Like' in VBA code (works fine in SQL -- ie:
queries). If you want to test the first character for "B", you need to
do what Doug suggested:

Select Case Left(Me.Combo28.Column(1) & "", 1)
Case "B"



Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




tony Jacobs wrote:
I tried the code without the left function, and my debugging message box
returns what is actually in the combobox column(1) which is any of the

below
criteria. here is the code:

.................................................. ...........................

.................................................. ...........................
.............

Debug.Print Me.Combo28.Column(1)

' Select Case Left(Me.Combo28 & "", 1)
' Select Case Left(Me![Combo28].Column(1), 1)

Dim myrpt As Variant
myrpt = Me.Combo28.Column(1)

Select Case myrpt

Case "Like'B*'"

stDocName = "Productsreport1"

Case "Like'C*'"

' Case Left(Me![Combo28].Column(1), 1) = "C"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select

MsgBox ("The ComboBox Value is " & Me.Combo28.Column(1)),

vbInformation,
" OOps "
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN " &
strSelected

EndIT:

End Sub

.................................................. ...........................

.................................................. ...........................
...................

the immediate window returns the following or has returned the following

( I
figured out how to work it now)
(below using the left statement)
L
L
L

using only the (Me.Combo28.Column(1))

Like 'C*'
Like 'C*'
Like 'C*'
Like 'P*'
Like 'B*'

.................................................. ...........................

.................................................. ...........................
....................

Still the report printed is the last one which is in the case else
condition.








"tony Jacobs" wrote in message
...
Okay a quick update: I put a message box that printed the value of the

Combo
box, and the left statement returns the letter "L" only

that's why the report selection is bypassed to the Case Else Statement

..

Please note that the coulmn(1) in the combobox is as follows

Column(1) is:
Like 'C*'
Like 'P*'
Like 'B*'
Like '*'
Like 'Z*'
Like"[b]*"
Like "[BC]*"


I am thinking of trying the combobox without the Left function.


"tony Jacobs" wrote in message
...
Compile Error
Expected Expression if I put ? Debug.Print

Left(Me.Combo28.Column(1)
&
"", 1) in thr immediate window

Also I get an error that the Value of the Combo Box is not set yet.or

not
calculated. I used to be able to use the immediate window very
successfully.
Please tell me if I am doing something wrong.

Thanks



"Damon Heron" wrote in message
...
Before the Select Case statement, put:

debug.print Left(Me.Combo28.column(1) & "",1)

if the correct answer appears in the immediate window, then you might
try:
dim myrpt as variant
myrpt= Left(Me.Combo28.Column(1) & "",1)
Select Case myrpt
Case "B"
...........
Case "C"
etc.

There is no way the correct report name would not be assigned to
stDocName
in this case.

Damon



"tony Jacobs" wrote in message
...
No Damon;

The problem is that the same report opens in all cases. Which means
that
the
case statement is not picking up the value of the combo box.
The open report works perfectly and it tells me which records in the
list
box it is about to print.

Now what I am trying to do is limit the list box to all items that
start
with a C, then print the C report

Limit items to all that start with a B then print all items that

Start
with
a B , then Print the B report (I called it report2 for example).

The "ProductID IN " & strSelected statement.is flawless. I worked it
out.
Happy 4th of July. Proud to be an American.

"Damon Heron" wrote in message
. ..
I would suggest you put a breakpoint at the beginning of your case
stmt
and
step thru the code, checking values-- if the code picks the correct
report
name, then the problem is in your DoCmd.OpenReport stDocName,
acViewPreview,
, "ProductID IN " & strSelected statement.

Damon


"tony Jacobs" wrote in message
...
Doug;

No luck. No Errors but no results.

Thanks for your time


"Douglas J. Steele" wrote in
message
...
Given you were trying to use Column(1) in your first example,

try
Select Case Left(Me.Combo28.Column(1) & "", 1)

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


"tony Jacobs" wrote in message
...
Sorry John; I did not work ! Any other ideas?


"John Spencer" wrote in message
...
Select Case Left(Me.Combo28 & "",1)

Case "B"
stDocName = "Productsreport1"

Case "C"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select

DoCmd.OpenReport stDocName, acViewPreview, , "ProductID

IN
"
&
strSelected


'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


strive4peace wrote:
hi Tony

"Me![Combo28].column(1) = Like'B*'"
-- left(Me![Combo28].column(1),1) = "B"

"Me![Combo28].column(1) = 'Like'C*''"
-- left(Me![Combo28].column(1),1) = "C"


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




tony Jacobs wrote:
I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value

of
the
combo
box,
and based on that it will select which report to print,

but
I
can
not
get it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID
IN
"
&
strSelected


Thanks in advance














  #24  
Old July 5th, 2008, 02:48 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
tony Jacobs
external usenet poster
 
Posts: 50
Default Case statement Problem not resolved Still

Doug;
The Value of the Me.Combo28.Column(1) is Like 'B*' , and any other
variations.(Like 'C*', etc.....). You helped me with this earlier on. The
lstbox gets poulated with items that start with a B when I select a combo
box value of Like 'B*', and so on.

No all I want to do is print the items in the lstbox , using the
corresponding report. i.e: print
the B* ( items that start with a B) on the B report (Report2) , C Items ..
By the way; I put a message box that returns the contents of
Me.Combo28.Column(1), and it returns the correct value.

I am thinking of using If statements. This is my first time using Case
statements. and the spaces between the Like and the first ' is correct,
only one space.

I am Stumped now.

"Douglas J. Steele" wrote in message
...
The problem would appear to be that the value in Me.Combo28.Column(1) is

not
what you're expecting it to be. In other words, whatever value is there
never starts with either a B or a C.

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


"tony Jacobs" wrote in message
...
Damon;
I tried your code and I added 3 message boxes at the end of the code to
see
the value of the stDocName and it is always the report name in the Case
else
statement.

It seems that we are close, but the conditional reports are not being
picked
up .


"Damon Heron" wrote in message
...
Before the Select Case statement, put:

debug.print Left(Me.Combo28.column(1) & "",1)

if the correct answer appears in the immediate window, then you might
try:
dim myrpt as variant
myrpt= Left(Me.Combo28.Column(1) & "",1)
Select Case myrpt
Case "B"
...........
Case "C"
etc.

There is no way the correct report name would not be assigned to
stDocName
in this case.

Damon



"tony Jacobs" wrote in message
...
No Damon;

The problem is that the same report opens in all cases. Which means
that
the
case statement is not picking up the value of the combo box.
The open report works perfectly and it tells me which records in the

list
box it is about to print.

Now what I am trying to do is limit the list box to all items that
start
with a C, then print the C report

Limit items to all that start with a B then print all items that

Start
with
a B , then Print the B report (I called it report2 for example).

The "ProductID IN " & strSelected statement.is flawless. I worked it

out.

Happy 4th of July. Proud to be an American.

"Damon Heron" wrote in message
. ..
I would suggest you put a breakpoint at the beginning of your case
stmt
and
step thru the code, checking values-- if the code picks the correct
report
name, then the problem is in your DoCmd.OpenReport stDocName,
acViewPreview,
, "ProductID IN " & strSelected statement.

Damon


"tony Jacobs" wrote in message
...
Doug;

No luck. No Errors but no results.

Thanks for your time


"Douglas J. Steele" wrote in
message
...
Given you were trying to use Column(1) in your first example, try

Select Case Left(Me.Combo28.Column(1) & "", 1)

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


"tony Jacobs" wrote in message
...
Sorry John; I did not work ! Any other ideas?


"John Spencer" wrote in message
...
Select Case Left(Me.Combo28 & "",1)

Case "B"
stDocName = "Productsreport1"

Case "C"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select

DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN

"
&
strSelected


'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


strive4peace wrote:
hi Tony

"Me![Combo28].column(1) = Like'B*'"
-- left(Me![Combo28].column(1),1) = "B"

"Me![Combo28].column(1) = 'Like'C*''"
-- left(Me![Combo28].column(1),1) = "C"


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




tony Jacobs wrote:
I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value of

the
combo
box,
and based on that it will select which report to print, but

I
can
not
get it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID

IN
"
&
strSelected


Thanks in advance




















  #25  
Old July 5th, 2008, 03:09 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
tony Jacobs
external usenet poster
 
Posts: 50
Default Case statement Problem

I got it Brutus........LoL

All code was good, problem was one space between the like and the 'C*' in
the case statement with the many iterations I may have Phat fingered it.
Thank you all for your time. A light bulb lit when crystal mentioned the
space. After I am done with this project, I'll try an If statement scenerio.

Thanks All. It works perfectly now. Thanks for getting me to use the
immediate window again. it's been 3 years.

Have a great week end. Now Me Go Get Some Brewskie !!!!

"tony Jacobs" wrote in message
...
I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value of the combo box,
and based on that it will select which report to print, but I can not get

it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN " &
strSelected


Thanks in advance




  #26  
Old July 5th, 2008, 03:18 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Case statement Problem

tony Jacobs wrote:

I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value of the combo box,
and based on that it will select which report to print, but I can not get it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN " &
strSelected



I think you are going about this the wrong way. The idea of
using Select Case for the Where clause from your table is
hard coding way too much.

I suggest that you add another field to the table. The
field would indicate which report should be used and can be
included in the combo box's RowSource as Column(2). This
way, the code would have no dependency on the where
condition.

If the field contains 1 for the Productsreport1 case, 2 for
Productsreport2 and nothing for when you want to use
Productsreport, then the code could simply be:

stDocName = "Productsreport" & Me.combo28.Column(2)
DoCmd.OpenReport stDocName, . . .

--
Marsh
MVP [MS Access]
  #27  
Old July 5th, 2008, 03:19 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Case statement Problem not resolved Still

If the combo box is returning Like 'B*', you need code like:

Select Case Nz(Me.Combo28.Column(1), "")
Case "Like 'B*'"
stDocName = "Productsreport1"
Case "Like 'C*'"
stDocName = "Productsreport2"
Case Else
stDocName = "Productsreport"
End Select


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


"tony Jacobs" wrote in message
...
Doug;
The Value of the Me.Combo28.Column(1) is Like 'B*' , and any other
variations.(Like 'C*', etc.....). You helped me with this earlier on. The
lstbox gets poulated with items that start with a B when I select a combo
box value of Like 'B*', and so on.

No all I want to do is print the items in the lstbox , using the
corresponding report. i.e: print
the B* ( items that start with a B) on the B report (Report2) , C Items ..
By the way; I put a message box that returns the contents of
Me.Combo28.Column(1), and it returns the correct value.

I am thinking of using If statements. This is my first time using Case
statements. and the spaces between the Like and the first ' is correct,
only one space.

I am Stumped now.

"Douglas J. Steele" wrote in message
...
The problem would appear to be that the value in Me.Combo28.Column(1) is

not
what you're expecting it to be. In other words, whatever value is there
never starts with either a B or a C.

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


"tony Jacobs" wrote in message
...
Damon;
I tried your code and I added 3 message boxes at the end of the code to
see
the value of the stDocName and it is always the report name in the Case
else
statement.

It seems that we are close, but the conditional reports are not being
picked
up .


"Damon Heron" wrote in message
...
Before the Select Case statement, put:

debug.print Left(Me.Combo28.column(1) & "",1)

if the correct answer appears in the immediate window, then you might
try:
dim myrpt as variant
myrpt= Left(Me.Combo28.Column(1) & "",1)
Select Case myrpt
Case "B"
...........
Case "C"
etc.

There is no way the correct report name would not be assigned to
stDocName
in this case.

Damon



"tony Jacobs" wrote in message
...
No Damon;

The problem is that the same report opens in all cases. Which means
that
the
case statement is not picking up the value of the combo box.
The open report works perfectly and it tells me which records in the
list
box it is about to print.

Now what I am trying to do is limit the list box to all items that
start
with a C, then print the C report

Limit items to all that start with a B then print all items that

Start
with
a B , then Print the B report (I called it report2 for example).

The "ProductID IN " & strSelected statement.is flawless. I worked it
out.

Happy 4th of July. Proud to be an American.

"Damon Heron" wrote in message
. ..
I would suggest you put a breakpoint at the beginning of your case
stmt
and
step thru the code, checking values-- if the code picks the correct
report
name, then the problem is in your DoCmd.OpenReport stDocName,
acViewPreview,
, "ProductID IN " & strSelected statement.

Damon


"tony Jacobs" wrote in message
...
Doug;

No luck. No Errors but no results.

Thanks for your time


"Douglas J. Steele" wrote in
message
...
Given you were trying to use Column(1) in your first example,
try

Select Case Left(Me.Combo28.Column(1) & "", 1)

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


"tony Jacobs" wrote in message
...
Sorry John; I did not work ! Any other ideas?


"John Spencer" wrote in message
...
Select Case Left(Me.Combo28 & "",1)

Case "B"
stDocName = "Productsreport1"

Case "C"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select

DoCmd.OpenReport stDocName, acViewPreview, , "ProductID
IN

"
&
strSelected


'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


strive4peace wrote:
hi Tony

"Me![Combo28].column(1) = Like'B*'"
-- left(Me![Combo28].column(1),1) = "B"

"Me![Combo28].column(1) = 'Like'C*''"
-- left(Me![Combo28].column(1),1) = "C"


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




tony Jacobs wrote:
I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value
of
the
combo
box,
and based on that it will select which report to print,
but

I
can
not
get it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID

IN
"
&
strSelected


Thanks in advance






















  #28  
Old July 6th, 2008, 05:56 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.reports
tony Jacobs
external usenet poster
 
Posts: 50
Default Case statement Excellent Idea

Excellent Idea. I love it. I will change it to that.

Thanks Marsh !!!


"Marshall Barton" wrote in message
...
tony Jacobs wrote:

I am having trouble with this code can anyone help.

I have the follwing case statement that checks the value of the combo

box,
and based on that it will select which report to print, but I can not get

it
to work

Select Case ReportPrint

Case "Me![Combo28].column(1) = Like'B*'"
stDocName = "Productsreport1"

Case "Me![Combo28].column(1) = 'Like'C*''"

stDocName = "Productsreport2"

Case Else

stDocName = "Productsreport"

End Select
DoCmd.OpenReport stDocName, acViewPreview, , "ProductID IN " &
strSelected



I think you are going about this the wrong way. The idea of
using Select Case for the Where clause from your table is
hard coding way too much.

I suggest that you add another field to the table. The
field would indicate which report should be used and can be
included in the combo box's RowSource as Column(2). This
way, the code would have no dependency on the where
condition.

If the field contains 1 for the Productsreport1 case, 2 for
Productsreport2 and nothing for when you want to use
Productsreport, then the code could simply be:

stDocName = "Productsreport" & Me.combo28.Column(2)
DoCmd.OpenReport stDocName, . . .

--
Marsh
MVP [MS Access]



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.