Witam społeczność,
Napisałem pewną funkcję w VBA. Oto jej kod:
Function Wylicz(addressCell As String, cityCell As String, startDate As String, endDate As String)
Dim address As String
Dim city As String
address = Replace(addressCell, " ", "%")
city = Replace(cityCell, " ", "%")
Dim objRec As ADODB.Recordset
Dim objConn As ADODB.Connection
Dim cmdString As String
'Set objRec = CreateObject("ADODB.Recordset")
'Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = "Driver={SQL Server};Server=serwer;Database=baza;User ID=user;Password=haslo"
objConn.Open
cmdString = "DECLARE @table AS TGroups" + Chr(13)
cmdString = cmdString + "GO" + Chr(13)
cmdString = cmdString + "INSERT INTO @table (groupName) VALUES ('Grupa1')" + Chr(13)
cmdString = cmdString + "GO" + Chr(13)
cmdString = cmdString + "INSERT INTO @table (groupName) VALUES ('Grupa2')" + Chr(13)
cmdString = cmdString + "GO" + Chr(13)
cmdString = cmdString + "INSERT INTO @table (groupName) VALUES ('Grupa3')" + Chr(13)
cmdString = cmdString + "GO" + Chr(13)
Set objRec = objConn.Execute(cmdString)
cmdString = "EXEC dbo.SprzedazPoAdresieDostawy @groups = @table, @address = address, @city = city, @startDate = startDate, @endDate = endDate"
Set objRec = objConn.Execute(cmdString)
If objRec.EOF = True Then
Wylicz = 0
Else
Wylicz = objRec!ACTINDX
End If
objConn.Close
End Function
Niestety, ale funkcja nie chce działać. W przypadku wywołania:
=Wylicz(C1;D1;"2024-04-01";"2024-04-30")
w komórce Excela pojawia się charakterystyczne #ARG!
Co jest nie tak?