Select Case Error

  • Thread starter Mary Bowman via AccessMonster.com
  • Start date
M

Mary Bowman via AccessMonster.com

I have the following code to send records based on the case to the form
that I have created. I keep getting the error "variable not found"
highlighting "RcdFilter"

Any suggestions???

Private Sub ADP_Click()

Dim sFilter As String
Select Case RcdFilter
Case 0
Case 1 sFilter = "[Companyid] = '2"
End Select
Me.Filter = sFilter
Me.FilterOn = Len(sFilter) > 0

DoCmd.OpenForm "frmPreview"
End Sub
 
D

Dirk Goldgar

"Mary Bowman via AccessMonster.com" <[email protected]>
wrote in message
I have the following code to send records based on the case to the
form that I have created. I keep getting the error "variable not
found" highlighting "RcdFilter"

Any suggestions???

Private Sub ADP_Click()

Dim sFilter As String
Select Case RcdFilter
Case 0
Case 1 sFilter = "[Companyid] = '2"
End Select
Me.Filter = sFilter
Me.FilterOn = Len(sFilter) > 0

DoCmd.OpenForm "frmPreview"
End Sub

I see nothing in the posted code that defines RcdFilter as a variable.
Is this a control on the form? Is it a variable that is defined at the
module level? Is it a global variable?
 
M

Mary Bowman via AccessMonster.com

RcdFilter is a tag on the form that is being opened. I fixed the tag, but
now the form brings up all the records and not filtering.
 
D

Dirk Goldgar

Mary Bowman via AccessMonster.com said:
RcdFilter is a tag on the form that is being opened. I fixed the
tag, but now the form brings up all the records and not filtering.

I'm not sure what you mean when you say "RcdFilter is a tag". However,
if you've "fixed it" in such a way that your code now compiles, then
maybe your problem comes from the fact this line:
Case 1 sFilter = "[Companyid] = '2"

has an unbalanced single-quote. Assuming [Companyid] is a text field,
that line should be:

Case 1 sFilter = "[Companyid] = '2'"

Note that, if [Companyid] is a numeric field (not text), that should
just be

Case 1 sFilter = "[Companyid] = 2"

Also, I see that you are applying this filter to the current form, and
then opening another form. Which form is it that you're expecting the
filter to be applied to? You're doing nothing to apply the filter to
"frmPreview".
 
M

Mary Bowman via AccessMonster.com

Hooray! That did it. I put the case on the other form. It works.

Thanks Dick!!!
 

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

Top