[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Autofill the city and state field in an Access 2007 subform by selecting a zip code

Posted on 2010-11-18
3
Medium Priority
?
643 Views
Last Modified: 2012-05-10
I want the [Zip] field in my subform (AddrDtl_frm) to autofill the [AddrDtCity] and [AddrDtCity] fields in the same subform based on the [Zip] selected in the combobox in the subform. The main form's recordsource is Addr_tbl.  The subform's recordsource is AddrDtl_tbl.  The subform and main form are linked through the [Addr] field.  Previous code worked great when I had a single form using one record source.  I'm sure I'm messing up the paths.  

Tables
Addr_Tbl
  Addr

AddrDtl_tbl
  AddrDtlLocTyp
  AddrDtlLocNum
  AddrDtCity
  AddrDtSt
  Zip
  Addr (Linked to Addr_tbl . Addr)

 Addr-tbl.doc
Private Sub Zip_AfterUpdate()
Dim varAddrDtCity, VarAddrDtSt As Variant
varAddrDtCity = DLookup("[AddrDtCity]", "Zip_tbl", "[ZipID]=Forms![Addr_Frm]![AddrDtl_frm].Form![ZipID] =" & Me!Zip)
 If (Not IsNull(varAddrDtCity)) Then Me![AddrDtCity] = Me!Zip.Column(2)
VarAddrDtSt = DLookup("[AddrDtSt]", "Zip_tbl", "[ZipID]=Forms![Addr_Frm]![AddrDtl_frm].Form![ZipID]=" & Me!Zip)
 If (Not IsNull(VarAddrSt)) Then Me![AddrSt] = Me!Zip.Column(3)

End Sub

*Worked Great when on a single form and one record source
Private Sub Zip_AfterUpdate()
Dim varAddrDtCity, VarAddrDtSt As Variant
varAddrDtCity = DLookup("AddrDtCity", "Zip_tbl", "[ZipID] =" & Me!Zip)
 If (Not IsNull(varAddrDtCity)) Then Me![AddrDtCity] = Me!Zip.Column(2)
VarAddrDtSt = DLookup("AddrDtSt", "Zip_tbl", "[ZipID]=" & Me!Zip)
 If (Not IsNull(VarAddrDtSt)) Then Me![AddrDtSt] = Me!Zip.Column(3)
End Sub

Open in new window

0
Comment
Question by:marksantelia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

Accepted Solution

by:
ste5an earned 2000 total points
ID: 34171766
hi Mark,

first a comment on your code: It's not possible to declare multiple variables by enumerating them. Thus

Dim lngVal1, lngVal2 As Long

will result in lngVal1 being a Variant and lngVal2 being a Long. So your code runs fine, but you should remember this and declare always every variable, as it makes code better readable.

As you said your messing up the paths: You don't need to use any path at all. So your single form code should work seamlessly.

btw, I think you don't need the DLookup()'s at all as you have already the necessary values loaded in your ZIP combo box...

mfG
--> stefan <--
Private Sub Zip_AfterUpdate()

  If Len(Trim(Me!Zip.Column(2))) > 0 Then 
    Me![AddrDtCity] = Me!Zip.Column(2)
  End If

  If Len(Trim(Me!Zip.Column(3))) > 0 Then 
    Me![AddrDtSt] = Me!Zip.Column(3)
  End If

End Sub

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36038826
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question