Hi Guy's would you be kind enough to tell me where this is wrong please ?
I am outputting 1 single record into tblJobSheets2 (this is to combine the quantity into 1 new record) there maybe 7 records for DelNo
Then trying to run an Insert SQL in the tblJobSheets
All is looking good apart from a refresh in the table (tblJobSheets), the data isn't transferring ?
The iJS (Job Sheet Number) should match in both tables
Code
Code:
If Forms!frmMainMenu!frmIndex3!txtCurrentSheet <> "" TheniJS = Forms!frmMainMenu!frmIndex3!txtCurrentSheet
If Not IsNull(strVehicle = DLookup("Vehicle", "tblJobSheets2", "[Driver] = '" & strDriver & "' And [DelDate] = #" & dtDelDate & "# And [DelNo] = " & intDelNo)) Then
DoCmd.CancelEvent
Else
Set rs2 = CurrentDb.OpenRecordset("Select * From tblJobSheets2")
strItems = DCount("DelTo", "tblAssign", "[PostCode] = '" & strPC & "' And [DeliveryDate] = #" & dtDelDate & "#")
If strItems >= 1 Then
strAddDel = DCount("DelTo", "tblAssign", "[PostCode] = '" & strPC & "' And [DeliveryDate] = #" & dtDelDate & "#") & " " & "Lifts"
End If
If strItems = 1 Then
strAddDel = DCount("DelTo", "tblAssign", "[PostCode] = '" & strPC & "' And [DeliveryDate] = #" & dtDelDate & "#") & " " & "Lift"
End If
If IsNull(strEntCode = DLookup("EntryCode", "tblDealers", "[PostCode] = '" & strPC & "'")) Then
strEntCode = ""
Else
strEntCode = DLookup("EntryCode", "tblDealers", "[PostCode] = '" & strPC & "'")
End If
If IsNull(strExtCode = DLookup("ExitCode", "tblDealers", "[PostCode] = '" & strPC & "'")) Then
strExtCode = ""
Else
strExtCode = DLookup("ExitCode", "tblDealers", "[PostCode] = '" & strPC & "'")
End If
With rs2
.AddNew
!IDNumber = iJS
!DelDate = dtDelDate
!Driver = strDriver
!Vehicle = strVehicle
!DelNo = intDelNo
!DelTo = Me.DelTo & "-" & Me.Town & "-" & Me.PostCode
!Items = strAddDel
!EntCode = strEntCode
!ExtCode = strExtCode
.Update
.Close
End With
Forms!frmMainMenu!frmIndex3!txtDropNo = Me.DelNo
strSQL = "INSERT INTO tblJobSheets ( Driver, DelDate, Del" & intDelNo & ", CartonQty" & intDelNo & ", EntCode" & intDelNo & ", ExCode" & intDelNo & " ) " _
& "SELECT tblJobSheets2.Driver, tblJobSheets2.DelDate, tblJobSheets2.DelTo, tblJobSheets2.Items, tblJobSheets2.EntCode, tblJobSheets2.ExtCode " _
& "From tblJobSheets2 " _
& "WHERE (((tblJobSheets2.IDNumber)= " & iJS & ") AND ((tblJobSheets2.DelNo) = " & intDelNo & "));"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Debug.Print strSQL
DoCmd.SetWarnings True
End If
End If
Immediate Window
Code:
INSERT INTO tblJobSheets ( Driver, DelDate, Del7, CartonQty7, EntCode7, ExCode7 ) SELECT tblJobSheets2.Driver, tblJobSheets2.DelDate, tblJobSheets2.DelTo, tblJobSheets2.Items, tblJobSheets2.EntCode, tblJobSheets2.ExtCode From tblJobSheets2 WHERE (((tblJobSheets2.IDNumber)= 5219) AND ((tblJobSheets2.DelNo) = 7));