Dlookup Query with two variables

I'm trying to do a Dlookup with two variables so that the record brought back from the
query qryAssignation will only be the records 1 to 8 in courseID and GroupID equal to value stored in the cbgroup Combo box but I do not seem to be able to get it to work.
Private Sub cbGroup_AfterUpdate()
Dim i As Integer
'i get the error here
For i = 1 To 8
  Me("lCourse" & i).Caption = Nz(DLookup("Course", "qryAssignation", (("CourseID=" & i) And "GroupID" = Me.cbGroup)))
Next
 
For i = 1 To 8
  Me("lTeacher" & i).Caption = Nz(DLookup("Teacher", "tblteacher", "TeacherID=" & i))
Next
 
End Sub

Open in new window

LVL 10
TOPIOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Try this for the first part:

For i = 1 To 8
  Me("lCourse" & i).Caption = Nz(DLookup("Course", "qryAssignation", "CourseID=" & i & " And [GroupID]  = " & Me.cbGroup))
Next

mx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
That assumes both CourseID and GroupID are numeric ... are they?

mx
0
TOPIOAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.