473,804 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dlookup help

Joe
I have a table with an sequence (PK) and 2 fields, employee id and
status id. Each employee can have multiple records in this table due
to multiple status ids assigned.

I have a multi-list box on a form which displays all possible statuses.

I want to write code to highlight all the statuses associated with the
employees id.

I currently have tried dlookup but cannot get it to work correctly.

'Populate list box with saved values (if any exist)
For x = 0 To Me!lststatus.Li stCount - 1

If emp_form.ItemDa ta(x) = DLookup("STATUS _ID", "EMP_STATUS ",
"EMP_ID = " & Me![emp id]) Then Me!lststatus.Se lected(x) = True

Next x

Any suggestions on what I am doing wrong? Will Dlookup return more
than one record if they exist?

Thanks!
Joe

Nov 13 '05 #1
4 3341
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Try this loop instead:

With Me!lstStatus
For each row = 0 to .ListCount - 1

.Selected(x) = .Column(col_n, x) =
DLookup("Status _ID", "Emp_Status ", "Emp_ID=" & Me![emp id])

next x
End With

The "col_n" in .Column(col_n, x) should be changed to the column number
(zero based) that holds the Status ID.
--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQeLq/IechKqOuFEgEQL5 7wCffozddV3BccV d03EF2X45ySdknr MAoKo+
3d1vRYForBx71du 3pTEFnQDG
=/rJU
-----END PGP SIGNATURE-----
Joe wrote:
I have a table with an sequence (PK) and 2 fields, employee id and
status id. Each employee can have multiple records in this table due
to multiple status ids assigned.

I have a multi-list box on a form which displays all possible statuses.

I want to write code to highlight all the statuses associated with the
employees id.

I currently have tried dlookup but cannot get it to work correctly.

'Populate list box with saved values (if any exist)
For x = 0 To Me!lststatus.Li stCount - 1

If emp_form.ItemDa ta(x) = DLookup("STATUS _ID", "EMP_STATUS ",
"EMP_ID = " & Me![emp id]) Then Me!lststatus.Se lected(x) = True

Next x

Any suggestions on what I am doing wrong? Will Dlookup return more
than one record if they exist?

Nov 13 '05 #2
Joe
I still have not been able to get this working. Dlookup only seems to
be returning the 1st record it finds and it still isn't highlighting
that one on the form.

Nov 13 '05 #3
Joe wrote:
I still have not been able to get this working. Dlookup only seems to
be returning the 1st record it finds and it still isn't highlighting
that one on the form.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well I screwed up the For...Next loop, and didn't think the thing thru.
Try this (stupidly, since I just did the same thing in my last project,
but don't have the code):

' Get the list of Statuses for the emp_id
dim db as dao.database
dim rs as dao.recordset
set db = currentdb
set rs = db.openrecordse t("SELECT Status_ID FROM Emp_status " & _
"WHERE emp_id = " & me![emp id])

With Me!lstStatus

' iterate thru rs & mark items in list box
do while not rs.eof
For x = 0 to .ListCount - 1
if .column(col_n, x) = rs(0) then
.selected(x) = true
exit for
end if
next x
rs.movenext
loop

End With

set rs = nothing
set db = nothing

The "col_n" in .Column(col_n, x) should be changed to the column number
(zero based) that holds the Status ID in the list box lstStatus.

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQeRVwYechKq OuFEgEQKcmgCcCh 8Xu/RZBd3TDzmu9ie4f hmioFwAnAs/
NWP+zf1LPM6n0TN pk9ZqI7WT
=wKlu
-----END PGP SIGNATURE-----
Nov 13 '05 #4
Hi,

Your problem is that, as you've written it, the DLookup always accesses
the first STATUS_ID for the EMP_ID. You should specify both EMP_ID and
STATUS_ID in the Where part of the DLookup:

....

If emp_form.ItemDa ta(x) = DLookup("STATUS _ID", "EMP_STATUS ", "EMP_ID =
" & Me![emp id] & " AND STATUS_ID = emp_form.ItemDa ta(x)) Then

Me!lststatus.Se lected(x) = True

End If

....

Try and let me know.
Mike Watson

MGFoster wrote:
Joe wrote:
I still have not been able to get this working. Dlookup only seems to be returning the 1st record it finds and it still isn't highlighting that one on the form.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well I screwed up the For...Next loop, and didn't think the thing

thru. Try this (stupidly, since I just did the same thing in my last project, but don't have the code):

' Get the list of Statuses for the emp_id
dim db as dao.database
dim rs as dao.recordset
set db = currentdb
set rs = db.openrecordse t("SELECT Status_ID FROM Emp_status " & _
"WHERE emp_id = " & me![emp id])

With Me!lstStatus

' iterate thru rs & mark items in list box
do while not rs.eof
For x = 0 to .ListCount - 1
if .column(col_n, x) = rs(0) then
.selected(x) = true
exit for
end if
next x
rs.movenext
loop

End With

set rs = nothing
set db = nothing

The "col_n" in .Column(col_n, x) should be changed to the column number (zero based) that holds the Status ID in the list box lstStatus.

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQeRVwYechKq OuFEgEQKcmgCcCh 8Xu/RZBd3TDzmu9ie4f hmioFwAnAs/
NWP+zf1LPM6n0TN pk9ZqI7WT
=wKlu
-----END PGP SIGNATURE-----


Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14942
by: Ronny Sigo | last post by:
Hello all, I already put the same question, only now I have more to tell ... Although I used this code before in the same routine (only the fieldname of the table differs) ___ at this point in the code I get the error "You canceled the previous operation" err msg. When clicking on Help I get a white screen. I haven't got the slightest idea what it means .... I pinned down that this error comes from the Dlookup function, because if I put...
6
2341
by: JLM | last post by:
What am I missing here? I have a form where I enter a "Class Code". This value corresponds to what sits in table "class code descriptions" along with the "title" of each "class code." Key field is "class code." I want a text box to be populated with the "title" which corresponds to the "class code" which I enter in the form. The control source for the text box is:
5
3203
by: Kalvin Schroder | last post by:
I am fairly new to Access, and am trying to put together an invoice form. The main form in called InvoiceDetailFm. Source is the table InvoiceDetail and has invoice number, saleman, and CustID as some of its fields. I have put together a combobox, named it CustID, and am trying to use DLookup() to bring the complete Customer Name etc onto the form using DLookup() function for the fields I need. The combobox will bring up the CustID in...
11
2877
by: Nick J | last post by:
Hi, I want t display several fields in one label box using the DLookUp function. I have tried using below but all I get is '-1' when I preview the report. Any idea's? =DLookUp("" And "","tblCompanyDetails") --
6
508
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as I've said. It doesn't populate until I go to a new record. Then if I go back to the record the number is in the field. Instead of populating immediately it waits until I've created a new record. Am I making sense with this description. Here's...
11
2236
by: MLH | last post by:
DLookup("", "tblPreliminaryVINs", "=Forms!frmVINODO!SerialNum") is giving me a Type Mismatch error. That's confusing to me and I don't know how to circumvent it. The field in tblPreliminaryVINs is a 17-char text field. Forms!frmVINODO!SerialNum is just an unbound textbox on a form (frmVINODO). I run the DLookup during the textbox's BeforeUpdate event code. Some VIN values I type in there do NOT give rise to the error. Some do. By
2
2277
by: Don | last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with Access. I've been creating databases for several years for work with the help of many of you and trial and error. I have used DLookup several times and I've actually re-created the same lookup just in different forms. Here's my problem. I'm using dlookup when I enter a part description it adds the part number for me. I choose the part description from a combo...
21
3378
by: Thelma Lubkin | last post by:
I would like my DLookup criteria to say this: Trim(fieldX) = strVar: myVar = _ DLookup("someField", "someTable", "Trim(fieldX) = '" & strVar & '") I don't believe that this will work, and I won't be at a machine with access to Access for a while, so can someone please tell me how to write this? thanks, --thelma
1
1807
by: aharding | last post by:
Hello! I am using Access 2003 I have been playing with DLookup all morning and have not been successful yet. I have never used this function...and have some limited experience with code. I will post what I have tried so far and hopefully someone can help me problem solve. I have tried three different methods... (I know Calculation is spelled wrong..I have to go through my database and fix it everywhere just haven't had the time...
15
3131
by: rleepac | last post by:
This is a little complicated but I'll do my best to explain. In my db I have a table called L_AgeCorrection which has the following fields: Age, Sex, Frequency, AgeValue This is a table used to assign an Age Correction value to hearing test results - since some degree of hearing loss naturally occurs with aging - OSHA lets us calculate that in before determining if the employee has an actual "significant" hearing loss. Anyway...I have my...
0
9571
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.