Setting the RecordSource in VBA

atrium

Registered User.
Local time
Today, 14:53
Joined
May 13, 2014
Messages
348
I have been using the Form_Load event with the following code.
The Values of Me.MatterIdFld and Me.ClientIdFld are set using openargs and their values for this exercise are 0

I have tried using the code using the Form_Open event

Code:
  Dim strOpenArgs() As String
  If Not IsNull(Me.OpenArgs) Then
    strOpenArgs = Split(Me.OpenArgs, ";")
    Me.[MatterIdFld].Value = Val(strOpenArgs(0))
    Me.[ClientIdFld] = Val(strOpenArgs(1))
  Else
    Me.ClientIdFld = 0
    Me.MatterIdFld = 0
  End If
  'MsgBox "MatterIdFld = " & Me.MatterIdFld
  ' If Me.MatterIdFld and Me.ClientIdFld = 0 then use the Login qry
  If Me.MatterIdFld > 0 Then
     Me.RecordSource = "APMatterActionTasksQry"
     Me.Filter = "MatterId = " & Me.MatterIdFld
     Me.FilterOn = True
     'MsgBox "Using APMatterActionTasksQry"
  Else
     If Me.ClientIdFld = 0 Then
        Me.RecordSource = "APLoginActionTasksQry"
        Me.Filter = "UserId = " & Me.UserIdFld
        Me.FilterOn = True
        'MsgBox "Using APLoginActionTasksQry"
     Else
        Me.RecordSource = "APClientActionTasksQry"
        Me.Filter = "ClientId = " & Me.ClientIdFld
        Me.FilterOn = True
        'Me.Filter = "ClientId = " & Me.ClientId
        Me.Requery
        'MsgBox "Using APClientActionTasksQry"
     End If
  End If

When I trace through the code after breaking at the first line in the event as both variables = 0 I want to set the RecordSource to "APLoginActionTasksQry" it happens and then set the Me.filter= "UserId = " & Me.UserIdFld and this works
BUT straight after that line it goes to the Form_Load Event???

Not sure what I can do

Any help will be appreciated
 
Might be better if you posted a copy of the database (zipped).
Remove or adjust anything private first.
 
I don't see how it can get to

Code:
Me.RecordSource = "APMatterActionTasksQry"
with

Code:
 If Me.MatterIdFld > 0 Then

being before it and MatterIdFld being equal to zero

Edit: I can see the Else part now. Guess I had a mini stroke
 
Last edited:
I have three variations of the values of Me.ClientIdFld and Me.MatterIdFld
They are :

0,0 where I want the RecordSource = "APLoginActionTasksQry"

1,0 where I want the RecordSource = "APClientActionTasksQry"

and

1,4902 where I want the RecordSource = "APMatterActionTasksQry"

The values 1 and 4902 are just examples
 
Sorry, I guess I was cross-eyed but I agree with Jdraw. I'd be better if we could look at this.
 
Why not set the recordsource at on load anyway ? Am I missing something ?
 

Users who are viewing this thread

Back
Top Bottom