Rowsource property of a subform via vba (1 Viewer)

LOUISBUHAGIAR54

Registered User.
Local time
Today, 01:00
Joined
Mar 14, 2010
Messages
157
I am trying to insert the rowsource property of a subform using vba, so that I can alter this accordingly.

The code goes on like this;

Private Sub cmdBilling_Click()

Dim sors As String

sors = " SELECT tblVarServices.Service, tblservicelog.invoiceno, tblservicelog.hospno, tblservicelog.ServiceRef, tblservicelog.servicedate, tblservicelog.invoiced, tblservicelog.paid, tblservicelog.item_amount, tblservicelog.itemprice, [itemprice]*[item_amount] AS Cost, tblservicelog.UserName" _
& " FROM tblVarServices INNER JOIN tblservicelog ON tblVarServices.ID = tblservicelog.ServiceRef" _
& " WHERE (((tblservicelog.Invoiced) = False))" _
& " ORDER BY tblservicelog.ID;"

If IsNull(Me.cltidcard) Then Exit Sub
DoCmd.OpenForm "FrmServices", , , acFormEdit
Forms!FrmServices.Filter = "[cltIdcard] = """ & Forms!frmClients!cltidcard & """"
Forms!FrmServices.FilterOn = True
Forms.FrmServices.FrmServicesub.Form.RowSource = sors
End Sub


However when I click the control which executes this vba sequence I get the following error message;



' Runtime error 2465;

application-defined or object-defined error.'

This error refers to the following line;

Forms.FrmServices.FrmServicesub.Form.RowSource = sors


Is this a sequenceing problem or is it a syntax error. Can I please get some help on this.

Many thanks for any help that will lead me to a solution.

LouisB
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:00
Joined
Aug 30, 2003
Messages
35,068
You want the RecordSource property.
 

LOUISBUHAGIAR54

Registered User.
Local time
Today, 01:00
Joined
Mar 14, 2010
Messages
157
Many thanks for your reply and help. However I changed the code to;

Forms.FrmServices.FrmServicesub.Form.RecordSource = sors
and still I am getting the same error.

Is there any other oversight I am falling prey to ?

LouisB
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:00
Joined
Aug 30, 2003
Messages
35,068
Try

Forms!

! instead of .
 

LOUISBUHAGIAR54

Registered User.
Local time
Today, 01:00
Joined
Mar 14, 2010
Messages
157
Many thanks.

The oversight I was falling prey to was a missing s. The real name of the subform is;
FrmServicesSub.

The code is working well now. The line now reads:

Forms.FrmServices.FrmServicesSub.Form.RecordSource = sors

Changing the . to a ! did not work as it was producing another error.

LouisB
 

Users who are viewing this thread

Top Bottom