JonathanB64
New member
- Local time
- Today, 18:50
- Joined
- Mar 18, 2016
- Messages
- 3
I am using MS Access 2016 and need to create a dynamic form that displays data from my Sql Server data. My stored procedure is a dynamic pivot query so the columns will change. I am thinking of setting the form's recordset to a local MS Access table. The dynamic part is a form with two date fields. This is my code so far:
Sub DynamicAudits()
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Dim sqlAudit
Set qdf = CurrentDb.CreateQueryDef("")
qdf.Connect = "ODBC;Driver=SQL Server;Server=XXXX;database=CAQA;UID=XXXX;PWD=XXXX;"
' stored procedure with parameter
qdf.SQL = "exec [CIP].[usp_Dynamic_Pivot_Reviews_Param] '" & [Forms]![frm_Audit_Param]![sdate] & "','" & [Forms]![frm_Audit_Param]![edate] & "'"
qdf.ReturnsRecords = True
Set rst = qdf.OpenRecordset
Set Me.Recordset = rst
DoCmd.SetWarnings False
sqlAudit = "Select * Into Audit From " & rst
DoCmd.SetWarnings True
ShowCrossTab
End Sub
Obviously, the sqlAudit string does not work but that is the goal I am working towards.
The function "ShowCrossTab" is the function that will actually build the form based on the new recordset.
So how can I create this new local table from my SQL Server data?
Sub DynamicAudits()
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Dim sqlAudit
Set qdf = CurrentDb.CreateQueryDef("")
qdf.Connect = "ODBC;Driver=SQL Server;Server=XXXX;database=CAQA;UID=XXXX;PWD=XXXX;"
' stored procedure with parameter
qdf.SQL = "exec [CIP].[usp_Dynamic_Pivot_Reviews_Param] '" & [Forms]![frm_Audit_Param]![sdate] & "','" & [Forms]![frm_Audit_Param]![edate] & "'"
qdf.ReturnsRecords = True
Set rst = qdf.OpenRecordset
Set Me.Recordset = rst
DoCmd.SetWarnings False
sqlAudit = "Select * Into Audit From " & rst
DoCmd.SetWarnings True
ShowCrossTab
End Sub
Obviously, the sqlAudit string does not work but that is the goal I am working towards.
The function "ShowCrossTab" is the function that will actually build the form based on the new recordset.
So how can I create this new local table from my SQL Server data?