DeveloperSteve
Registered User.
- Local time
- Today, 15:25
- Joined
- May 21, 2012
- Messages
- 12
I'm trying to use VBA to open a datasheet based on a SQL Server stored procedure. The stored procedure requires parameters. This seems simple enough, but I'm having trouble. My code is below. I'm having trouble setting the the datasheet's recordsource to the recordset.
Function LADatasheet015(strWhere As String, strQueried As String)
Dim cmd As ADODB.Command
Dim parameters As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
Dim xmlParams As String
Dim rs As ADODB.Recordset
'create property list in XML format for Where In statement for sproc
strWhere = strWhere & ","
xmlParams = Replace(strWhere, "',", "</value>")
xmlParams = "'<values>" & Replace(xmlParams, "'", "<value>") & "</values>'"
parameters = "'" & PublicFunctions.GetRegionForUser() & "', " & xmlParams
cmd.CommandText = "EXEC 015Datasheet" & parameters
cmd.CommandTimeout = 300
rs = cmd.Execute
Forms!frm015Datasheet.RecordSource = rs
DoCmd.OpenForm "frm015Datasheet"
End Function
Function LADatasheet015(strWhere As String, strQueried As String)
Dim cmd As ADODB.Command
Dim parameters As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
Dim xmlParams As String
Dim rs As ADODB.Recordset
'create property list in XML format for Where In statement for sproc
strWhere = strWhere & ","
xmlParams = Replace(strWhere, "',", "</value>")
xmlParams = "'<values>" & Replace(xmlParams, "'", "<value>") & "</values>'"
parameters = "'" & PublicFunctions.GetRegionForUser() & "', " & xmlParams
cmd.CommandText = "EXEC 015Datasheet" & parameters
cmd.CommandTimeout = 300
rs = cmd.Execute
Forms!frm015Datasheet.RecordSource = rs
DoCmd.OpenForm "frm015Datasheet"
End Function