O
ormazd
I've been scratching my head on this for a while. In theory, this function
will open 2 tables, perform comparisons and update records when 3 conditions
are met. I'm not popping any errors, but it won't advance past the first
record. Any help would be appreciated!
------------------------------------------------------------------------------------------------
Option Compare Database
Option Explicit
Dim dbMyDB As DAO.Database, MyWorkspace As DAO.Workspace
'This routine looks for two files...one with available drop locations, one
with pallets to locate
Dim DROPS As DAO.Recordset
Dim LOCS As DAO.Recordset
Dim Unassigned As Integer
Dim Capacity As Integer
Dim In_Use As Integer
Dim Drop_1 As String
Dim Pallets As Integer
Dim LOCS_Run As String
Dim DROPS_Run As String
Dim LOCS_UOW As String
Dim DROPS_UOW As String
Dim LOCS_Location As String
Function ASSIGN_LOCS()
Set MyWorkspace = DBEngine.Workspaces(0)
Set dbMyDB = CurrentDb
Set DROPS = dbMyDB.OpenRecordset("Current Auto Drops", , dbOpenDynaset)
Debug.Print "Recordset name and type: " & DROPS.Name & vbTab & _
DROPS.Type
Debug.Print "Recordset updatable?: " & DROPS.Updatable
Set LOCS = dbMyDB.OpenRecordset("Auto Drop Locs", , dbOpenDynaset)
Debug.Print "Recordset name and type: " & LOCS.Name & vbTab & _
LOCS.Type
Debug.Print "Recordset updatable?: " & LOCS.Updatable
Unassigned = DROPS![Unassigned Pallets]
Capacity = LOCS![Capacity]
In_Use = LOCS![In Use]
Drop_1 = DROPS![Drop Zone Loc 1]
Pallets = DROPS![Pallets]
LOCS_Run = LOCS![Run Number]
DROPS_Run = DROPS![Run Number]
LOCS_UOW = LOCS![UOW]
DROPS_UOW = DROPS![UOW]
LOCS_Location = LOCS![Location]
DROPS.MoveFirst
LOCS.MoveFirst
Do While Not DROPS.EOF
With LOCS
Do While Not .EOF
If Unassigned >= Capacity Then
If In_Use = 0 Then
If Drop_1 = "*" Then
'Record must meet all 3 conditions to call update
ASSIGN_LOC
ASSIGN_DROP
Else: .MoveNext
If .EOF Then Exit Function
End If
Else: .MoveNext
If .EOF Then Exit Function
End If
Else: .MoveNext
If .EOF Then Exit Function
End If
Loop
End With
DROPS.MoveNext
If DROPS.EOF Then Exit Function
Loop
MsgBox ("All done!")
DROPS.Close
Set DROPS = Nothing
LOCS.Close
Set LOCS = Nothing
will open 2 tables, perform comparisons and update records when 3 conditions
are met. I'm not popping any errors, but it won't advance past the first
record. Any help would be appreciated!
------------------------------------------------------------------------------------------------
Option Compare Database
Option Explicit
Dim dbMyDB As DAO.Database, MyWorkspace As DAO.Workspace
'This routine looks for two files...one with available drop locations, one
with pallets to locate
Dim DROPS As DAO.Recordset
Dim LOCS As DAO.Recordset
Dim Unassigned As Integer
Dim Capacity As Integer
Dim In_Use As Integer
Dim Drop_1 As String
Dim Pallets As Integer
Dim LOCS_Run As String
Dim DROPS_Run As String
Dim LOCS_UOW As String
Dim DROPS_UOW As String
Dim LOCS_Location As String
Function ASSIGN_LOCS()
Set MyWorkspace = DBEngine.Workspaces(0)
Set dbMyDB = CurrentDb
Set DROPS = dbMyDB.OpenRecordset("Current Auto Drops", , dbOpenDynaset)
Debug.Print "Recordset name and type: " & DROPS.Name & vbTab & _
DROPS.Type
Debug.Print "Recordset updatable?: " & DROPS.Updatable
Set LOCS = dbMyDB.OpenRecordset("Auto Drop Locs", , dbOpenDynaset)
Debug.Print "Recordset name and type: " & LOCS.Name & vbTab & _
LOCS.Type
Debug.Print "Recordset updatable?: " & LOCS.Updatable
Unassigned = DROPS![Unassigned Pallets]
Capacity = LOCS![Capacity]
In_Use = LOCS![In Use]
Drop_1 = DROPS![Drop Zone Loc 1]
Pallets = DROPS![Pallets]
LOCS_Run = LOCS![Run Number]
DROPS_Run = DROPS![Run Number]
LOCS_UOW = LOCS![UOW]
DROPS_UOW = DROPS![UOW]
LOCS_Location = LOCS![Location]
DROPS.MoveFirst
LOCS.MoveFirst
Do While Not DROPS.EOF
With LOCS
Do While Not .EOF
If Unassigned >= Capacity Then
If In_Use = 0 Then
If Drop_1 = "*" Then
'Record must meet all 3 conditions to call update
ASSIGN_LOC
ASSIGN_DROP
Else: .MoveNext
If .EOF Then Exit Function
End If
Else: .MoveNext
If .EOF Then Exit Function
End If
Else: .MoveNext
If .EOF Then Exit Function
End If
Loop
End With
DROPS.MoveNext
If DROPS.EOF Then Exit Function
Loop
MsgBox ("All done!")
DROPS.Close
Set DROPS = Nothing
LOCS.Close
Set LOCS = Nothing