Change RecorSource Property Of Subform inside Main Form

  • Thread starter Thread starter hallian92
  • Start date Start date
H

hallian92

Guest
Hi,

Is there any way I can change the Record Source Property of my subform inside the Main Form programmatically. I have a subform inside my Main Form. What I want is whenever I click a Button that is inside my Main Form I want to change the Record Source Property of my subform. At design time I have set the following as follows:

Main Form:
Record Source = query1

subform:
Record Source = query1

When I click the Button inside my Main Form at run-time I want to change the Record Source Property as follows:

sub Button_Click()
Dim rstSerialNumbers As Recordset
Dim dbsSerialNumbers As Database
Dim qdfSerialNumbers As QueryDef
Dim strSQLSerialNumbers As String
Set dbsSerialNumbers = CurrentDb
Set qdfSerialNumbers = dbsSerialNumbers.CreateQueryDef("")
strSQLSerialNumbers = strSQLSerialNumbers & "SELECT * FROM [Items] WHERE "
strSQLSerialNumbers = strSQLSerialNumbers & "Ship Like " & "'*" & intItemIDTable & "*' And Shed=Yes "
strSQLSerialNumbers = strSQLSerialNumbers & "ORDER BY ItemID DESC; "
qdfSerialNumbers.sql = strSQLSerialNumbers
Set rstSerialNumbers = qdfSerialNumbers.OpenRecordset

'Here I have change the Record Source Property Of the Main For

Me.RecordSource = strSQLSerialNumbers

'Now I also want to cganhe the Record Source of the subform

Me.[subform].RecordSource = strSQLSerialNumbers
................
................

Can I change the subform Record Source Property if not is there any way I can achieve this. Thanks for any help.
I tried to use this but gives me an error

Me.<subformName>.RecordSource = SQLSTr

Thanks for any help.
 

Users who are viewing this thread

Back
Top Bottom