Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 22nd, 2006, 08:17 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help - Dlookup function

Hi,
    I'm using Dlookup function to return a value.
E.g

Dim strName as string
me.txtName.value=strName

If strName = Dlookup("[EmpName]","EmpTable","[EmpID]=" & 1) then
....

[EmpName] and [EmpID] are 2 colummes from the table. If strName matches the [EmpName] in the EmpTable, i should get the corresponding EmpID nos and compare with the value, e.g 1 in this case. But it is not working if there are 2 or more similar value in the EmpID field.

Pls kindly advise or how should my statement looks like?? Thnks alot.

Rgds,
Andy


  #2 (permalink)  
Old August 23rd, 2006, 10:47 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I would set the variable value like this:

strName = Me.txtName.Value

Why would there be 2 or more duplicate values in the Primary Key column?



mmcdonal
  #3 (permalink)  
Old August 23rd, 2006, 11:26 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
   I set '1' for some users in the primary key and '2' for the others.
Supposingly, if dlookup return '1', a set of operations with be carried out whereby if return '2' another set of operations with be carried out.... but it is not working if there are more than 2 similar value in the same field.

Rgds.

  #4 (permalink)  
Old August 23rd, 2006, 11:30 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

That is your problem. You are not properly using the Primary Key field.

If you have a column that you want either 1 or 2 in, use a check box which will store the values 0 and -1, then use those for your functions.

Use the PK field as a unique identifier. This function that you are attempting will not work until you insert an autonumber PK field into your table.



mmcdonal


Similar Threads
Thread Thread Starter Forum Replies Last Post
vb DLOOKUP function and dialog box error bluezcruizer Beginning VB 6 2 January 18th, 2007 04:25 PM
Dlookup and variables Jaqx Access 3 September 29th, 2006 06:47 AM
Help with DLookup Devilboy13 Access VBA 4 August 30th, 2006 02:48 PM
DLookup Teqlump Access VBA 1 August 9th, 2006 11:48 PM
Dlookup function giving Type Mismatch error Ron V Access 2 May 19th, 2004 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.