I have a customers form (based on the customers table). I need for a value from another table (a table named addresses) be placed in a field on my customers form based on the value of the address field in the customers form. For example... I start to enter new customer data, then after I enter the address, lets sat 123 Main St., I need the DB to lookup "Main St". from the addresses table and tell me what days it is serviced and enter that value in the Service Days field of the customers table/form. BTW, the Addresses table is basically just a list for service days of all streets serviced.
I figured to just do this in the after update event of the adderss field. I placed a dlookup function to retrieve the value but I cant get the syntax correct. I have the following:
After that code is ran I get the following error:
Runtime Error 3075: Syntax error (missing operator) in query expression 'streetname = main st'
"main st" being the address I entered for the customer
What am I doing wrong??
Now, to expand on this... Once I get that above code working, I need to figure out how to update all previous customers to update the service days field automatically. This code or function is something that will only need to be performed once (or if the service day for any street ever changes which is very rare). I was thinking just a button somewhere that did the following, but needs to be translated into code:
"open customers table/form and go to first record"
"lookup current address in Addresses table to get service days value"
"enter value in service days field"
"go to next record and repeat till the last record is updated"
I would figure an update query, but I dont know how to set different criteria for each record to be updated. How would I go about doing this also? Thanks for any help!!!
I figured to just do this in the after update event of the adderss field. I placed a dlookup function to retrieve the value but I cant get the syntax correct. I have the following:
Code:
Dim Days As String
Dim CurrentStreet As String
'[COLOR=green]remove the house number leaving just the street name[/COLOR]
CurrentStreet = Mid(Nz([Address]), InStr(Nz([Address]), " ") + 1)
[COLOR=green]'lookup the value in the Addresses table that matches the current street[/COLOR]
Days = Nz(DLookup("days", "addresses", "streetname = " & CurrentStreet), "")
Me.Service_Days = Days
After that code is ran I get the following error:
Runtime Error 3075: Syntax error (missing operator) in query expression 'streetname = main st'
"main st" being the address I entered for the customer
What am I doing wrong??
Now, to expand on this... Once I get that above code working, I need to figure out how to update all previous customers to update the service days field automatically. This code or function is something that will only need to be performed once (or if the service day for any street ever changes which is very rare). I was thinking just a button somewhere that did the following, but needs to be translated into code:
"open customers table/form and go to first record"
"lookup current address in Addresses table to get service days value"
"enter value in service days field"
"go to next record and repeat till the last record is updated"
I would figure an update query, but I dont know how to set different criteria for each record to be updated. How would I go about doing this also? Thanks for any help!!!