If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > dlookup returns frist value in feild

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-12, 23:08
jkisner jkisner is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
Question dlookup returns frist value in feild

Hi All,
i could use your help, I have two tables my call log tabe that has a combox with zip codes that i am using, cazip table that has my zip codes and the state codes (shown below).
zip - statecode
61721 - 13
61007 - 15

i created a form so that when i change the zip dlookup will return the state code for me in the box that labeled statecode.... Currently when i change the zip code it only returns the frist value in side the colum of state codes.

exp

zip=61007
statecode=13

so this is my current dlookup script

Private Sub CBOZIP_AfterUpdate()
STATECODE = DLookup("[STATECODE]", "[CAZIP]", "[CBOZIP]=" & CBOZIP)

what do i need to do to make it pull the state code that matches the zip.

i am very new to this as in the last week so most of my learning is hands on and that not much. any help would be great
Thanks
jkisner

Last edited by jkisner; 01-19-12 at 23:10. Reason: wording backwards
Reply With Quote
  #2 (permalink)  
Old 01-20-12, 00:56
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
Would this be simpler for you?

Autofill
__________________
Paul
Reply With Quote
  #3 (permalink)  
Old 01-21-12, 12:57
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
Is the Field in the CAZIP Table actually named CBOZIP? If so, what is its Datatype?

Fields composed entirely of Digits but not used for mathematical calculations are usually defined as Text, and your syntax is only correct if CBOZIP is defined as a Number.Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
  #4 (permalink)  
Old 01-22-12, 00:10
jkisner jkisner is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
reply

Hi
Thanks for your help it is currently has a data type as a number.
Reply With Quote
  #5 (permalink)  
Old 01-22-12, 09:17
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
Please confirm that the Field in the Table is actually named CBOZIP? I assume that CBOZIP is a Combobox that has the Zips in it, but that's an odd name for a Field in a Table.

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
  #6 (permalink)  
Old 01-22-12, 13:48
jkisner jkisner is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
REply

hi thanks for you help. The table fields are ID,STATECODE,ZIP,CITY,COUNTY the primery Key is Zip . Im not sure if that matters but thought i would let you know incase it does if you need any othere info please let me know. Thanks again for your help.
Reply With Quote
  #7 (permalink)  
Old 01-22-12, 19:15
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
If the Table Field is named ZIP then your code needs to be

DLookup("[STATECODE]", "[CAZIP]", "[ZIP]=" & CBOZIP)

Of course, since ZIP and STATECODE are in the same Table, the standard way of doing this would be to have both ZIP and STATECODE in the CBOZIP's RowSource, and then use this code to populate the STATECODE Textbox:
Code:
Private Sub CBOZIP_AfterUpdate()
  Me.STATECODE = Me.CBOZIP.Column(1)
End Sub
assuming that the STATECODE was the 2nd Field in the Combobox, reading left-to-right; the Column Index is Zero-based.

This would alleviate the need to use DLookUp() altogether.

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
  #8 (permalink)  
Old 01-22-12, 22:03
jkisner jkisner is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
Reply

Thanks, I took your second option and it worked great. Now if i want to take the value given in the STATECODE and look for othere items in a differnt table. would i need to us DLookup for that. THANKS FOR YOUR HELP
Reply With Quote
  #9 (permalink)  
Old 01-22-12, 23:02
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
Yes, DLookUp would be the way to go, assuming that the other Table had a Field that would match STATECODE.

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
  #10 (permalink)  
Old 01-23-12, 00:23
jkisner jkisner is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
Thanks

Thanks for all your help i have it up and going and it is all looking good. now i just need to figure out mult user stuff. Which i well post a new thread if need be. Thanks again for all your help. have a good day
Reply With Quote
  #11 (permalink)  
Old 01-23-12, 08:21
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
Glad we could help!

Good luck with your project!

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On