Need Case Select Solution

  • Thread starter Steven Glass via AccessMonster.com
  • Start date
S

Steven Glass via AccessMonster.com

Does anyone have Case Select code for this?

I have a form with buttons(for each company) on it and when clicked should
bring up another form with data records for that particular company. Each
button represent a company set of records. When I click on a
button,another form opens with data records for that company. When I click
on another button the same form opens but with data records for the new
button
just clicked.

What is the best way on load of the 2nd form to change the set of records
on load? I’m also changing the label to reflect the new set of records.

Below is my filter code that I’m using on load of the 2nd form:

Private Sub Form_Load()

Dim sFilter As String
sFilter = "[Companyid] = 2"
Me!HeaderNm.Caption = "ADP - Preview"

Me.Filter = sFilter
Me.FilterOn = Len(sFilter) > 0


End Sub

Thanks,
Steven
 
J

jokobe

I usually solve this type of problem like this:

when pushing the button and opening the form first fill a hidden field in
that form
( CaseSelector = 1 for company 1, 2 for the second company ....)
after that:
sFilter = "[Companyid] = " & CaseSelector & "
Me.Filter = sFilter
Me.Filter = true

guess that should work

jokobe
 
S

Steven Glass via AccessMonster.com

Received Variable not defined.........

This is my code on the button:

Private Sub ADP_Click()

DoCmd.OpenForm "frmPreview"
Dim sFilter As String
sFilter = "[Companyid] = 2"

Me.Filter = sFilter
Me.FilterOn = Len(sFilter) > 0
CaseSelector = 1
sFilter = "[Companyid] = " & CaseSelector & ""

End Sub

THIS IS MY CODE ON FORM OPEN:

Private Sub Form_Open(Cancel As Integer)
Select Case Companyid
Case 0 'show all records
' do nothing
Case 1 sFilter = "[Companyid] = 2"
Me!HeaderNm.Caption = "ADP - Preview"
End Select

End Sub
 
K

Klatuu

Put the company code in the OpenArgs of the OpenForm statement. Pass it an
empty string if you don't want to filter on company.

In the Open event of the form you are opening, if the OpenArgs parameter is
empty, set your filer off, otherwise, assign the value to the filter and
apply the filter
 

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

Similar Threads


Top