ник: user12345
функция
Public Function TurnCr(ACC As String, STDATE, ENDDATE) As Double
Dim ACC1 As String, DDTE As String, DDTE2 As String, KUT As String, TURN As Double
DDTE = Format$(STDATE, "DD/MM/YYYY")
DDTE2 = Format$(ENDDATE, "DD/MM/YYYY")
If DLookup("ACCKUT", "ACC", "ACC = '" & [ACC] & "'") <> "" Then ACC1 = DLookup("ACCKUT", "ACC", "ACC = '" & [ACC] & "'") & "*" Else ACC1 = ""
On Error GoTo Err_TURNCR
Dim rstTURNCR As DAO.Recordset
Set rstTURNCR = CurrentDb.OpenRecordset("SELECT Sum(ACCTurn.AccSumm) AS SumOfAccSumm FROM Doc1 INNER JOIN (ACCTurn INNER JOIN ACC ON ACCTurn.AccCr = ACC.ACC) ON Doc1.DID = ACCTurn.ADID WHERE (((Doc1.Date)Between # " & DDTE & " # And # " & DDTE2 & " #) AND ((ACC.ACCKUT) like '" & ACC1 & "'))")
If IsNumeric(rstTURNCR!SumOfAccSumm) Then TURN = rstTURNCR!SumOfAccSumm Else TURN = 0
TurnCr = Round(TURN, 2)
rstTURNCR.Close
Set rstTURNCR = Nothing
Exit_TURNCR:
Exit Function
Err_TURNCR:
TurnCr = 0
Resume Exit_TURNCR
End Function
Заполнение шаблона ексел
Private Sub Command33_Click()
Dim Date1 As Date, Date2 As Date
Date1 = Format$(ot, "DD/MM/YYYY")
Date2 = Format$(dot, "DD/MM/YYYY")
tok = SqlLookUp("select function from TABFunction where Row=" & 1)
fileXLT = CurrentProject.Path & "\HASH2.xls"
Set ExcelApplication = CreateObject("Excel.Application")
With ExcelApplication
.Workbooks.Open fileXLT
.Visible = True
End With
Set ExcelWorksheet = ExcelApplication.Sheets(1)
ExcelApplication.Cells(1, 2).Value = DLookup("[function]", "TABFunction", "[Row] = 1") '-функция с параметрами сохранена в таблице и с помощю dlookup хочу вывести и заполнить ексел как в строке (1), но выводит и заполняет текст функции а не его итог
ExcelApplication.Cells(2, 2).Value = TurnCr("6111", Date1, Date2) '----------------(1)----------функция работает нормально
End Sub