Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto-entering new fields in a primary table

Status
Not open for further replies.

Glacil

MIS
Jul 7, 2004
9
US
I've been trying to make a field (Cities) in a joined table update to reflect when a new city entry is made in a form where the city is not already included in the cities tbl. Each city has a unique autonumber, which serves as the primary key. If I were to use the city name itself as a primary key, i know a variation of this MVB code would work:

If Len(Nz(Me.[tblCity.City], "")) = 0 Then
Me.[tblCity.City]=[tblComputers.City]
End If

But since each city has an ID and that is what is linking it to the foreign key in the table, (and I'm using a multibox to look up the city name itself through the city ID number), using this code would only work if the joining factor was the city name itself. Help! Any thoughts would be appreciated. Am I doing this linking properly, or should I just use the city name? I was under the impression that it is always much better to join with numbers rather than strings, so I have been trying to avoid making this change. Finding a way to do it in its current state would certainly eliminate some redundancy.
 
Whether you use the CityName or a CityID as the primary key, I suspect the real solution is to use DLookup...

[tt]
If Len(Nz(Me.[tblCity.City], "")) = 0 Then
Me.[tblCity.City]=DLookup("[CityName]", "tblComputers", "[CityID] = " & Me.YourCityID)
End If
[/tt]

I do not know the nanes of your ID fields, but hopeuflly you get the idea.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top