[AccessD] Cannot set recordsource on Load Event

Steve Schapel miscellany at mvps.org
Sat Jan 26 15:38:51 CST 2008


Randall,

Ah, now I see what you mean.  You are using a Where Condition in your 
OpenForm method.  I sorta didn't notice that before.  Yes, subsequently 
setting the Record Source property will obviously overwrite the Where 
Condition previously applied.

Ok, as a concept, here's how I would do it:

Form A
DoCmd.OpenForm "Audit Entry", , , , , , "1"

Form B
Private Sub Form_Open(Cancel As Integer)
      If Me.OpenArgs = "1" Then
          Me.RecordSource = "SELECT * FROM Audit_Data_Med WHERE <your 
criteria>"
      Else
          Me.RecordSource = "Audit_Data_MH"
      End If
End Sub

Hard to shoot in the dark here, without knowing what the mysterious 
Criteria is all about.  But it could be that this is more applicable 
concept:

Form A
DoCmd.OpenForm "Audit Entry", , , , , , Criteria

Form B
Private Sub Form_Open(Cancel As Integer)
      If Len(Me.OpenArgs) Then
          Me.RecordSource = "SELECT * FROM Audit_Data_Med WHERE " & 
Me.OpenArgs
      Else
          Me.RecordSource = "Audit_Data_MH"
      End If
End Sub

... Or:

Form A
DoCmd.OpenForm "Audit Entry", , , , , , "1" & Criteria

Form B
Private Sub Form_Open(Cancel As Integer)
      If Me.OpenArgs Like "1*" Then
          Me.RecordSource = "SELECT * FROM Audit_Data_Med WHERE " & 
Mid(Me.OpenArgs, 2)
      Else
          Me.RecordSource = "SELECT * FROM Audit_Data_MH WHERE " & 
Me.OpenArgs
      End If
End Sub

Regards
Steve


Randall Anthony wrote:
> I sorry I didn't make myself clear.  I have also just placed a line of code
> in the OpenForm event Me.Recordsource = "Audit_Data_Med" and it still
> returns all records.  
> 
> Could setting the criteria be the problem?  That I can't apply a filter to
> the form while dynamically setting the recordsource?



More information about the AccessD mailing list