Rowsource

MartijnAn

Registered User.
Local time
Today, 02:19
Joined
Sep 30, 2004
Messages
51
Hi All,

I have a question:

I have 3 forms (a,b,c). Forms A and B are seperate forms and C will be activated by either A or B. The recordsource of C is a query which can be:

[forms]![formA]![text1] = Qr1
[forms]![formB]![text2] = Qr2

How can I write a code (or adjust it in the query) that that lets form C change it's rowsource in Qr1 or Qr2?
 
Use the Open event of form C.

i.e.

Code:
Private Sub Form_Open(Cancel As Integer)
    ' put your evaluation code in here
    Me.RecordSource = [i]relevantControlReference[/i]
End Sub
 
Thanks,

But the problem is that I want to tell the Open_form event that the rowsource depends if I came from formA or from formB.
 
When opening the form, use the open args.

i.e

Code:
DoCmd.OpenForm "FormName", , , , , , Me.Name

That way, in the Form_Open event you can use the following:

Code:
Select Case Me.OpenArgs
    Case Is = "Form A"
        Me.RecordSource = "Query1"
    Case Is = "Form B"
        Me.RecordSource = "Query2"
    Case Else
        MsgBox "Unknown caller", vbExclamation, "Error"
        Cancel = True
End Select
 
Thanks,

I thinks this will help.
 
Last edited:
Listbox rowsource

I am having a similar problem, and this is the closest post I have found to answering my question, but it is not quite there!

My situation is that form A and form B can be used to open form C, like MartijnAn. However, depending on which form is used to reach form C, I need to change the RowSource of a ListBox on form C to one of two queries.

I am having all sorts of trouble. Once the 'open' command is fired from either form A or B, the listbox is immediately looking for parameters for the queries beforeany code can be used to set the rowsource in either the Open, Load or Activate events.

This is the code from forms A and B which open form C:
Code:
'Open form
DoCmd.OpenForm "frmOutputs_9_Track_Invoices", , , , , , 2

Code:
'Open form
DoCmd.OpenForm "frmOutputs_9_Track_Invoices", , , , , , 1

This is the code for when form C opens:
Code:
Private Sub Form_Open(Cancel As Integer)

Select Case Me.OpenArgs
    Case 1 'frmOutputs_2_Specific_Search_Results' was used
        Me.lstResults.RowSource = "qryOutputs_9_Track_Invoices1"
    Case 2 'frmInputs_14_Track_Invoice' was used
        Me.lstResults.RowSource = "qryOutputs_9_Track_Invoices2"
End Select

End Sub

Any suggestions?

EDIT:
I have even tried resetting the rowsource to an empty string on closing form C, but this won't save!!! The rowsource is still set to one of the queries when I open form C again.

Code:
Private Sub Form_Close()

Me.lstResults.RowSource = ""
DoCmd.Save acForm, Me.Name

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom