afh110
01-22-2010, 02:35 PM
Hi guys,
Im stuck and im sure you guys can make the difference
In the code below im trying to pass a parameter (Master_Key) to my saved query (BSC_View) and call it into my subform. I know how to pass a parameter to a saved query but when i need to set the query or query string (after i passed the parameter) to the "SourceObject" of my Subform my code gives me an error. Not sure how to do that. My code is below. Mind you the following facts:
Application :Access 2007
OS: Windows XP
[VBA]
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim db As DAO.Database
Dim rs As DAO.recordset
Dim strResult As String
Dim StrSQL As String
Dim qdf As QueryDef
Dim rst As recordset
Dim BSC_Master_Key As String
Set db = CurrentDb
BSC_Master_Key = Forms!Data_Management!DD_BSCDef_BSCRecord
Set qdf = db.QueryDefs("BSC_View")
qdf.Parameters(0) = BSC_Master_Key
StrSQL = qdf.sql
Forms!BSC_View!DS_BSC_View.SourceObject = "Query.BSC_View" '<<<<<----Need to set SourceObject to "BSC_VIEW" query with its set parameter!!
'rst.Close
qdf.Close
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
End Sub
Im stuck and im sure you guys can make the difference
In the code below im trying to pass a parameter (Master_Key) to my saved query (BSC_View) and call it into my subform. I know how to pass a parameter to a saved query but when i need to set the query or query string (after i passed the parameter) to the "SourceObject" of my Subform my code gives me an error. Not sure how to do that. My code is below. Mind you the following facts:
Application :Access 2007
OS: Windows XP
[VBA]
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim db As DAO.Database
Dim rs As DAO.recordset
Dim strResult As String
Dim StrSQL As String
Dim qdf As QueryDef
Dim rst As recordset
Dim BSC_Master_Key As String
Set db = CurrentDb
BSC_Master_Key = Forms!Data_Management!DD_BSCDef_BSCRecord
Set qdf = db.QueryDefs("BSC_View")
qdf.Parameters(0) = BSC_Master_Key
StrSQL = qdf.sql
Forms!BSC_View!DS_BSC_View.SourceObject = "Query.BSC_View" '<<<<<----Need to set SourceObject to "BSC_VIEW" query with its set parameter!!
'rst.Close
qdf.Close
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
End Sub