This one is going to be confusing to explain, but in reality is simpler. I am wondering the correct structure for certain tables regarding customers.
I'll start with the end result of what I need. I have a customers form with, amongst general customer data has a service days field and a driver field. I need the AfterUpdate of the address field to "lookup" what days that street is serviced and enter that day/value in the service day field, also do the same for the driver field.
My question would be in the way to structure the "lookup". Right now I have a single table named Addresses that lists: all the streets we service (Street field) the days they are serviced (Days field), and the driver who services that street (Driver field). I originally started with just a dlookup function to COPY the value from the Addresses table to the field in the customers table. (This function completed through the afterupdate property of the customers table though.) Technically speaking this works, but I just cant get the syntax right for the dlookup function:
But then I remembered reading somewhere that if you have a table with the same value repeated many times through the table, it is good practice to split that table into two or more. This would be the case, since the Addressed table; Days field are only 1 of 3 choices (Mon - Thurs, Tues - Fri, or Wed - Sat) each being repeated several hundered times. And then that data wold be repeated AGAIN in the Customers table. (Same principal for the Driver field). So if this WOULD be the correct way to structure it, what new tables would I need, how would I link them together, and finally how would I get the form to "lookup" the correct data for the address of the customer? Or if it is just easier with the dlookup function above, can someone tell me why that is not working?
I'll start with the end result of what I need. I have a customers form with, amongst general customer data has a service days field and a driver field. I need the AfterUpdate of the address field to "lookup" what days that street is serviced and enter that day/value in the service day field, also do the same for the driver field.
My question would be in the way to structure the "lookup". Right now I have a single table named Addresses that lists: all the streets we service (Street field) the days they are serviced (Days field), and the driver who services that street (Driver field). I originally started with just a dlookup function to COPY the value from the Addresses table to the field in the customers table. (This function completed through the afterupdate property of the customers table though.) Technically speaking this works, but I just cant get the syntax right for the dlookup function:
Code:
Private Sub Address_AfterUpdate()
Dim ServiceDays As String
Dim CurrentStreet As String
[COLOR=seagreen]'Removes the house number of the address leaving just the street name[/COLOR]
CurrentStreet = Mid(Nz([Address]), InStr(Nz([Address]), " ") + 1)
ServiceDays = Nz(DLookup("days", "addresses", "street = " & CurrentStreet), "")
Me.Service_Days = ServiceDays
End Sub
But then I remembered reading somewhere that if you have a table with the same value repeated many times through the table, it is good practice to split that table into two or more. This would be the case, since the Addressed table; Days field are only 1 of 3 choices (Mon - Thurs, Tues - Fri, or Wed - Sat) each being repeated several hundered times. And then that data wold be repeated AGAIN in the Customers table. (Same principal for the Driver field). So if this WOULD be the correct way to structure it, what new tables would I need, how would I link them together, and finally how would I get the form to "lookup" the correct data for the address of the customer? Or if it is just easier with the dlookup function above, can someone tell me why that is not working?