PDA

View Full Version : Lookup function in VBA



kapil2828
07-06-2011, 05:51 AM
Hi

In access form i have field called Customer and report name and due_date. Here i want to lookup the due_date value from the table once i have selected the customer and report name.

Any one can provide me theVB code for the ablove requirement.

Regards
Kabilan

hansup
07-06-2011, 07:40 AM
See whether the Access help topic for the DLookup() function is useful to you.

If you encounter trouble, paste in code you've tried and tell us as much as you can about why it fails. Include the full text of any error messages you receive.

kapil2828
07-07-2011, 03:27 AM
Thank you for the reply
I tryed Dlookup function and i got the value for the table, But its not repeating . value is fixed..

Code:
Private Sub Report_title_lostfocus()
Dim dd_find As Date
dd_find = DLookup("Due_Date", "report_details", Customer = Me!Customer.Value And Report_title = Me!Report_title.Value)
Due_Date.Value = dd_find
End Sub

Thanks again

HiTechCoach
07-07-2011, 08:03 AM
PMFJI...

Try:

d_find = DLookup("Due_Date", "report_details", "Customer = " & Me!Customer & " And Report_title = " Me!Report_title)

This assumes that both Me!Customer and Me!Report_title are numeric values. Usually the primary key value.

If they are actually text values then you will have to wrap the values with quotes using ( " ) or Chr(34) .

Example is text:
d_find = DLookup("Due_Date", "report_details", "Customer = " & Chr(34) & Me!Customer & Chr(34) & " And Report_title = " & Chr(34) & Me!Report_title & Chr(34))