VBA Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a question regarding DLookup - I have set my form up so that when a
MISNumber is populate the RptName should automatically populate with the
report that is associated with the MISNumber. Everytime I run it I get a
Debug error. This is the information that I have associated with the after
update of the MISNumber

Private Sub cboMISNumber_AfterUpdate()
Me.txtRptName = DLookup("[RptName]", "[tblCorrWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")
Me.txtRptName = DLookup("[RptName]", "[tblQueueWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")

End Sub

The debug error highlights the whole first line. Can someone please tell me
what I may be doing wrong. I have this code in other forms that I have
created and it works fine.

Thank you
 
What error message are you getting? Have you confirmed the correct spelling
of the table and field names?

Also, it looks like the second statement will overwrite the return value
from the first statement. This shouldn't cause an error, but it makes the
first statement useless.

Barry
 
I have other code written that states if Corr is choosen then I have a list
that populates a combo box - if Queue is choosen then a different list
populates the combo box. From that combo box I want it to populate the
report name based on what was previously choosen.


The error message that I am getting is "Data type mismatch in criteria
expression

Barry Gilbert said:
What error message are you getting? Have you confirmed the correct spelling
of the table and field names?

Also, it looks like the second statement will overwrite the return value
from the first statement. This shouldn't cause an error, but it makes the
first statement useless.

Barry

WMorsberger said:
I have a question regarding DLookup - I have set my form up so that when a
MISNumber is populate the RptName should automatically populate with the
report that is associated with the MISNumber. Everytime I run it I get a
Debug error. This is the information that I have associated with the after
update of the MISNumber

Private Sub cboMISNumber_AfterUpdate()
Me.txtRptName = DLookup("[RptName]", "[tblCorrWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")
Me.txtRptName = DLookup("[RptName]", "[tblQueueWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")

End Sub

The debug error highlights the whole first line. Can someone please tell me
what I may be doing wrong. I have this code in other forms that I have
created and it works fine.

Thank you
 
What you've got should work If MSINumber is a text field. If it's actually a
numeric field, get rid of the single quotes.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


WMorsberger said:
I have other code written that states if Corr is choosen then I have a list
that populates a combo box - if Queue is choosen then a different list
populates the combo box. From that combo box I want it to populate the
report name based on what was previously choosen.


The error message that I am getting is "Data type mismatch in criteria
expression

Barry Gilbert said:
What error message are you getting? Have you confirmed the correct
spelling
of the table and field names?

Also, it looks like the second statement will overwrite the return value
from the first statement. This shouldn't cause an error, but it makes the
first statement useless.

Barry

WMorsberger said:
I have a question regarding DLookup - I have set my form up so that
when a
MISNumber is populate the RptName should automatically populate with
the
report that is associated with the MISNumber. Everytime I run it I get
a
Debug error. This is the information that I have associated with the
after
update of the MISNumber

Private Sub cboMISNumber_AfterUpdate()
Me.txtRptName = DLookup("[RptName]", "[tblCorrWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")
Me.txtRptName = DLookup("[RptName]", "[tblQueueWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")

End Sub

The debug error highlights the whole first line. Can someone please
tell me
what I may be doing wrong. I have this code in other forms that I have
created and it works fine.

Thank you
 
Try this instead:

Me.txtRptName = DLookup("[RptName]", "[tblCorrWork]",
"[MISNumber]=" & Me.cboMISNumber)

This assumes that your MISNumber field is numeric. Numeric criteria don't
need quotes around them.

Barry

WMorsberger said:
I have other code written that states if Corr is choosen then I have a list
that populates a combo box - if Queue is choosen then a different list
populates the combo box. From that combo box I want it to populate the
report name based on what was previously choosen.


The error message that I am getting is "Data type mismatch in criteria
expression

Barry Gilbert said:
What error message are you getting? Have you confirmed the correct spelling
of the table and field names?

Also, it looks like the second statement will overwrite the return value
from the first statement. This shouldn't cause an error, but it makes the
first statement useless.

Barry

WMorsberger said:
I have a question regarding DLookup - I have set my form up so that when a
MISNumber is populate the RptName should automatically populate with the
report that is associated with the MISNumber. Everytime I run it I get a
Debug error. This is the information that I have associated with the after
update of the MISNumber

Private Sub cboMISNumber_AfterUpdate()
Me.txtRptName = DLookup("[RptName]", "[tblCorrWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")
Me.txtRptName = DLookup("[RptName]", "[tblQueueWork]",
"[MISNumber]='" & Me.cboMISNumber & "'")

End Sub

The debug error highlights the whole first line. Can someone please tell me
what I may be doing wrong. I have this code in other forms that I have
created and it works fine.

Thank you
 

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

Similar Threads

Query Help 3
Type mismatch in function called in report OnOpen event 3
Cannot trap 2501 error 5
Email attachments 3
Save dialog box 2
DLookup error 1
Can't get the code to sort the data properly. 2
dlookup 2

Back
Top