Change Recordset On Form Load

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

Steven Glass via AccessMonster.com

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
 
Steven said:
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

Have you tried using "Docmd.OpenForm"?

Here is code for one button:

'***begin code ****
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stOpenArgs As String

stDocName = "Form2"

'** change company ID and Openargs
' for each button (Company)
stLinkCriteria = "[Companyid] = 2"
stOpenArgs = "ADP - Preview"

DoCmd.OpenForm stDocName, , , stLinkCriteria, , , stOpenArgs

Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub
'*** end code ***


Then in the form set the caption using:

'***begin code ****
Private Sub Form_Open(Cancel As Integer)
Me!HeaderNm.Caption = Me.OpenArgs
End Sub
'*** end code ***

HTH
 
Back
Top