Predmet:Re: Funkcija molim pomoć
Uspio sam na kraju ovako:
PreuzmiIzvorni kôd (vbnet):Function Storniraj(OrderID As String)
On Error GoTo Err_Storniraj
Dim Db As Database
Dim Rs1 As Recordset
Dim Rs2 As Recordset
Dim Rs3 As Recordset
Dim SQL1 As String
Dim SQL2 As String
Dim SQL3 As String
Dim IDTransakcije As Integer
Set rcs = Nothing
Set Db = CurrentDb()
If Not IsNull(DLookup("[IDtransakcije]", "TblTransakcije", "[BrDokumenta] ='" & OrderID & "'")) Then
IDTransakcije = DLookup("[IDtransakcije]", "TblTransakcije", "[BrDokumenta] ='" & OrderID & "'")
SQL1 = "SELECT * FROM tblTransakcije WHERE BrDokumenta='" & OrderID & "'"
SQL2 = "SELECT * FROM tblUlazIzlaz WHERE IDTransakcije=" & IDTransakcije
Set Rs1 = Db.OpenRecordset(SQL1, dbOpenDynaset)
Set Rs2 = Db.OpenRecordset(SQL2, dbOpenDynaset)
If Rs1.RecordCount > 0 Then
Do While Not Rs1.EOF
Rs1.Edit
Rs1!Brisanje = 0
Rs1.Update
Rs1.MoveNext
Loop
End If
If Rs2.RecordCount > 0 Then
Do While Not Rs2.EOF
Rs2.Edit
Rs2!Status = 0
Rs2.Update
Rs2.MoveNext
Loop
End If
SQL3 = "SELECT * FROM tblProdaja WHERE OrderID='" & OrderID & "'"
Set Rs3 = Db.OpenRecordset(SQL3, dbOpenDynaset)
If Rs3.RecordCount > 0 Then
Do While Not Rs3.EOF
Rs3.Edit
Rs3!Proknjizeno = False
Rs3!Stornirano = 0
Rs3.Update
Rs3.MoveNext
Loop
End If
Rs1.Close
Rs2.Close
Rs3.Close
Else
SQL3 = "SELECT * FROM tblProdaja WHERE OrderID='" & OrderID & "'"
Set Rs3 = Db.OpenRecordset(SQL3, dbOpenDynaset)
If Rs3.RecordCount > 0 Then
Do While Not Rs3.EOF
Rs3.Edit
Rs3!Proknjizeno = False
Rs3!Stornirano = 0
Rs3.Update
Rs3.MoveNext
Loop
End If
Rs3.Close
End If
Set Db = Nothing
Izlaz:
Exit Function
Err_Storniraj:
MsgBox "Greska broj " & err.Number & vbCrLf & err.Description & vbCrLf & "u funkciji Storniraj()"
Kraj:
End Function
Dodao sam :
If Not Is Null (...) Then
Else
End if
I sada je sve u redu.
Pozdrav