Hi All.
The code I have below is meant to run for the amount of records found in the 'QueryBarcodeScannerReturns'. At the moment I have ten records in the query and the code is looping ten times on the same record, but not moving to the next record. I am sure something simple just needs to be added or removed to make this work.
Can anybody spot why this may be happening?
Thanks
The code I have below is meant to run for the amount of records found in the 'QueryBarcodeScannerReturns'. At the moment I have ten records in the query and the code is looping ten times on the same record, but not moving to the next record. I am sure something simple just needs to be added or removed to make this work.
Can anybody spot why this may be happening?
Thanks
Code:
Dim db As DAO.Database
Dim REC, REC2, REC3, REC4 As Recordset
Dim strSql As String
Dim TotalRecords As Integer
Dim TotalExistingRecords As Integer
Dim n As Integer
Dim LastID As Integer
Dim YesOrNo As Integer
' Count records in found set
Set db = CurrentDb()
Set REC = db.OpenRecordset("QueryBarcodeScannerReturns", dbOpenDynaset)
If REC.EOF Then REC.Close: Exit Sub
REC.MoveLast
TotalRecords = REC.RecordCount
REC.Close
' Get out message
Message = "MediPool will automatically update " & TotalRecords & _
" records in the Pool Bookings records."
Title = "Medipro2000 Auto PPM Job Builder"
Response = MsgBox(Message, vbOKCancel, Title)
For n = 1 To TotalRecords
YesOrNo = DCount("BookingID ", "QueryPoolBookingsDateInIsNull", "[CodeNo] = '" & Me.BarcodeValue & "'")
If YesOrNo > 0 Then
LastID = Nz(DMax("BookingID ", "PoolBookings", "[CodeNo] = '" & Me.BarcodeValue & "'"))
'Update PoolBookings with Returns Information
strSql = "SELECT * FROM [PoolBookings] WHERE [BookingID] = " & LastID & ""
Set db = CurrentDb()
Set REC = db.OpenRecordset(strSql, dbOpenDynaset)
Set REC2 = db.OpenRecordset("ReturningEquipmentScanner", dbOpenDynaset)
REC.Edit
REC("DateIn") = Date
REC("TimeIn") = Time()
REC("BookedInBy") = "Test"
REC("DepartmentBookingIn") = "Test"
REC.Update
REC2.Edit
REC2("Status") = "Processed"
REC2.Update
REC.MoveNext
REC2.MoveNext
Else
'Update - No History of Equipment being booked out, so new record added to PoolBookings
Set db = CurrentDb()
Set REC2 = db.OpenRecordset("ReturningEquipmentScanner", dbOpenDynaset)
Set REC3 = db.OpenRecordset("PoolBookings", dbOpenDynaset)
Set REC4 = db.OpenRecordset("ImportEquipment", dbOpenDynaset)
REC3.Edit
REC3.AddNew
REC3("CodeNo") = Me.BarcodeValue
REC3("DateOut") = Date - 1
REC3("TimeOut") = Time()
REC3("DateIn") = Date
REC3("TimeIn") = Time()
REC3("BookedOutBy") = "Not Recorded"
REC3("DepartmentBookingOutNotInList") = "Not Recorded"
REC3("BookedInBy") = DLookup("FullName", "Login", "[TempVars]![tvarUser]=[Username]")
REC3("DepartmentBookingIn") = "Equipment Pool"
REC3.Update
REC2.Edit
REC2("Status") = "Processed"
REC2.Update
REC3.MoveNext
REC2.MoveNext
End If
Next n