Hi guys. I have the following code and want to add a DLOOKUP, I'll try elaborating as I go.
I know it will look like a lot but my only trouble is understanding how to use DAO recordsets in DLOOKUPS. It's simple when you understand it (to code), but I've tried many variations and can't grasp it.
This is the code I have been working on.
I am hoping to set up a DLOOKUP for the Desk. The desk has to read from a second table (named DeskLookup).
I want the DLOOKUP to: Read rs1("Agent") and use it to lookup the connecting desk in DeskLookup and then paste it back in. Now it's important it does this as a lookup because I used to have a query that would update it all but it messed with a lot of other fields I had manually entered earlier in the code so I can't run an UPDATE QUERY on this like I had tried before.
I know it looks like a lot but my only trouble is understanding how to use DAO recordsets in DLOOKUPS. Any help is appreciated.
I know it will look like a lot but my only trouble is understanding how to use DAO recordsets in DLOOKUPS. It's simple when you understand it (to code), but I've tried many variations and can't grasp it.
Code:
If Not (rs1.EOF And rs1.BOF) Then
rs1.MoveFirst
Do Until rs1.EOF = True
If rs1("ID") = "X" And IsNull(rs1("Comments")) Then
If rs1("Indicator") = "1" Then
rs1.Edit
rs1("Comments") = "Manual review needed.”
rs1.Update
Else
If Not (rs2.EOF And rs2.BOF) Then
Do Until rs2.EOF = True
If rs1("UNIQUEID") <> rs2("UNIQUEID") Then
GoTo MoveNextrs2
End If
If rs1("Quantity") = rs2("Quantity”) Then
If rs1("Price") = "Buy" And rs2("Price") = "S" Then
rs1.Edit
rs1("Agent") = rs2("Agent")
rs1.Update
' VarX = DLookup GOES HERE
rs1.Edit
rs1("Desk") = VarX
rs1.Update
rs1.Edit
rs1("Comments") = rs1("Desk") & " – Please report.”
rs1.Update
rs2.MoveLast
ElseIf rs1("Price") = "Sell" And rs2("Price") = "B" Then
rs1.Edit
rs1("Agent") = rs2("Agent")
rs1.Update
' VarX = DLookup GOES HERE
rs1.Edit
rs1("Desk") = VarX
rs1.Update
rs1.Edit
rs1("Comments") = rs1("Desk") & " – Please report.”
rs1.Update
rs2.MoveLast
Else
GoTo MoveNextrs2
End If
End If
MoveNextrs2:
rs2.MoveNext
Loop
End If
End If
End If
rs1.MoveNext
Loop
End If
I am hoping to set up a DLOOKUP for the Desk. The desk has to read from a second table (named DeskLookup).
I want the DLOOKUP to: Read rs1("Agent") and use it to lookup the connecting desk in DeskLookup and then paste it back in. Now it's important it does this as a lookup because I used to have a query that would update it all but it messed with a lot of other fields I had manually entered earlier in the code so I can't run an UPDATE QUERY on this like I had tried before.
I know it looks like a lot but my only trouble is understanding how to use DAO recordsets in DLOOKUPS. Any help is appreciated.