What is wrong with my code?



I have a form that I am trying to change the background color for the
controls on that form if the name of the control (text or combo boxes) exist
in a query called "qryauditFieldNames" I am getting an error message on the
dlookup statment. It seems that I have the --- ("" & txt & "", --- syntax
wrong. can some one help me fix this or if some one has a better way to do
this, I will be very appreciative.
See the code below:

Dim ctl As Control, frm As Form, cbo As ComboBox, txt As TextBox

Set frm = Me.Form

With ctl
For Each ctl In frm.Controls
If ctl.controltype = acComboBox Or ctl.controltype = acTextBox Then
txt = ctl.Name
If ctl.Name = DLookup("" & txt & "", "qryauditFieldNames",
"RevisedField='" & ctl.Name & "'") Then
ctl.BackColor = vbRed
End If
End If
End With



Carl Rapson

You shouldn't need the quotes arount the txt value:

DLookup(txt, "qryauditFieldNames", "RevisedField='" & ctl.Name & "'")

Carl Rapson

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question