G
Guest
I used the wizard to link two forms by means of a command button
(cmdOpenSubs) on one form (frmAgents) that opens a second form
(frmSubclients) filtered to display the records that relate to a control
value on the currently displayed first form.
So when the value for the field (PrmClntID) in the relevant control on the
first form is the value for "Agent X", the second form opens filtered for
records with "Agent X".
This works, except that if I add new records in the filtered second form
then the form is no longer specific to the “Agent X†value. I get the
existing records for "Agent X", but if I enter a new records the filter falls
away and I have to re-enter the value for "Agent X" each time.
Same problem occurs if I use a form and subform, though linked forms are
more suitable here.
Here is the code the wizard generated for the command button. I know very
little about VBA, but would it be possible to tweak this code to get around
the problem?
Private Sub cmbOpenSubs_Click()
On Error GoTo Err_cmbOpenSubs_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSubclients"
stLinkCriteria = "[PrmClntID]=" & Me![txtPrmCntID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmbOpenSubs_Click:
Exit Sub
Err_cmbOpenSubs_Click:
MsgBox Err.Description
Resume Exit_cmbOpenSubs_Click
End Sub
(cmdOpenSubs) on one form (frmAgents) that opens a second form
(frmSubclients) filtered to display the records that relate to a control
value on the currently displayed first form.
So when the value for the field (PrmClntID) in the relevant control on the
first form is the value for "Agent X", the second form opens filtered for
records with "Agent X".
This works, except that if I add new records in the filtered second form
then the form is no longer specific to the “Agent X†value. I get the
existing records for "Agent X", but if I enter a new records the filter falls
away and I have to re-enter the value for "Agent X" each time.
Same problem occurs if I use a form and subform, though linked forms are
more suitable here.
Here is the code the wizard generated for the command button. I know very
little about VBA, but would it be possible to tweak this code to get around
the problem?
Private Sub cmbOpenSubs_Click()
On Error GoTo Err_cmbOpenSubs_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSubclients"
stLinkCriteria = "[PrmClntID]=" & Me![txtPrmCntID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmbOpenSubs_Click:
Exit Sub
Err_cmbOpenSubs_Click:
MsgBox Err.Description
Resume Exit_cmbOpenSubs_Click
End Sub