473,378 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Using DLookup to Lookup another table if value is blank

Help I am stumped;

I am trying to get DLookup to use the email value from another table if a user does not exist in the first table.
Expand|Select|Wrap|Line Numbers
  1. i = DLookup("email", "Member", "windowsname = text114")
  2. If i = "" Then
  3. emailaddress = DLookup("[email]", "Manager", "[username] = text114")
  4. Else
  5. emailaddress = i
Mar 29 '10 #1
8 5742
missinglinq
3,532 Expert 2GB
Per Access Help
If no record satisfies criteria or if domain contains no records, the DLookup function returns a Null.
So the correct test would be

If IsNull(i) Then

Linq ;0)>
Mar 29 '10 #2
I guess I didn't explain myself well in my post; here goes.

The emailaddress value which is being captured using the DLookup function is then going to be stored in another table called "Input". My problem is when I use the code below
Expand|Select|Wrap|Line Numbers
  1. i = DLookup("email", "Member", "windowsname = text114")
  2. If isnull(i) Then
  3. emailaddress = DLookup("[email]", "Manager", "[username] = text114")
  4. Else
  5. emailaddress = i
the email value is not being captured (I have a field in the input table called emailaddress to store this captured value and it's blank) and stored in the input table and neither is the second part of the if statement being fulfilled.

The whole event is trigged through a button click.

Thank you
Mar 29 '10 #3
NeoPa
32,556 Expert Mod 16PB
When posting any code on here please :
  1. Ensure you have Option Explicit set (See Require Variable Declaration).
  2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
  3. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
  4. Ensure that the code in your post is enveloped within CODE tags (For more on this see BB Code List). The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.
If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.
Mar 29 '10 #4
NeoPa
32,556 Expert Mod 16PB
Frankly there's so much off in your code it's hard to know where to start. A more carefully phrased question might have avoided some of the confusion.

The most glaring issue is that your use of what is probably a TextBox control on your form (text114) is not valid. DLookup, being SQL based as it is, would have no direct link to your form or its controls (It wouldn't recognise the name). If you were to use a more standard approach and add the value of the control to the string parameter as a literal, then quotes (') (See Quotes (') and Double-Quotes (") - Where and When to use them) would be needed. A bit like :
Expand|Select|Wrap|Line Numbers
  1. i = DLookup("email", "Member", "[windowsname] = '" & Me.text114 & "'")
Mar 29 '10 #5
Find my code below

The emailaddress is being captured when the user exists in the manager table; however the emailaddress is not captured when the user only exists in the member table. I need this emailaddress to be captured because in another procedure this emailaddress is used to send an email using this email address (emailaddress value is stored in another table called purchasetable)
Expand|Select|Wrap|Line Numbers
  1. Private Sub purchase_Click()
  2. Dim mess_body As String
  3. Dim ref As String
  4. Dim appOutLook As Outlook.Application
  5. Dim MailOutLook As Outlook.MailItem
  6. Set appOutLook = CreateObject("Outlook.Application")
  7. Set MailOutLook = appOutLook.CreateItem(olMailItem)
  8. Set appOutLook = CreateObject("Outlook.Application")
  9. Set MailOutLook = appOutLook.CreateItem(olMailItem)
  10. Text114 = Environ("username")
  11. MemServ = DLookup("[Forename]&' '&[Surname]", "Member", "[windowsname] = text114")
  12. Date_Completed = Now()
  13. i = DLookup("email", "Member", "[windowsname] = '" & Me.Text114 & "'")
  14. If IsNull(i) Then
  15. emailaddress = DLookup("email", "Manager", "[username] = '" & Me.Text114 & "'")
  16. Else
  17. i = emailaddress
  18. If IsNull(DLookup("[windowsname]", "Member", "windowsname = '" & Me.Text114 & "'")) And IsNull(DLookup("[username]", "Manager", "username = '" & Me.Text114 & "'")) Then
  19. MsgBox "You Are Not Authorized To Use This Form"
  20. Else
  21. If Val(Me.Wire_Amount) > DLookup("Limit", "Member", "windowsname = '" & Me.Text114 & "'") Then
  22.  MsgBox "Amount Over approval limit, Please Assign to Your Manager"
  23. Else
  24. With MailOutLook
  25.     .BodyFormat = olFormatRichText
  26.     .To = emailaddress
  27.     .Subject = "PURCHASE TRANSFER"
  28.     .Send
  29. End With
  30. MsgBox "A Notification Email Has Been Sent"
  31. 'MsgBox MailOutLook.Body
  32. Exit Sub
  33. email_error:
  34. MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
  35. Resume Error_out
  36. Error_out:
  37. End If
  38. End If
  39. End If
  40. End Sub
Mar 30 '10 #6
NeoPa
32,556 Expert Mod 16PB
To be honest I have no desire to continue on a thread where you cannot maintain a dialogue. Your post in no way includes any reference to any of my previous attempts to assist, and actually breaks the site rules again, in a way you've already been explicitly instructed about. Quite apart from the peremptory and demanding tone of the post.

Good luck.
Mar 30 '10 #7
I am sorry if my request came across as demanding. Did not in anyway mean that.

Sorry if I upset you

Thank you
Mar 31 '10 #8
NeoPa
32,556 Expert Mod 16PB
I'm thoroughly mollified (I'm happy with your response), but I still feel it will be difficult to work on this even though your manners are not an issue.

To work together there needs to be better communication. Without that it is simply a sequence of restarting from scratch. Progress is very difficult. I still wish you luck, and I'm not offended, I simply won't continue in this thread.
Apr 8 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tripp Knightly | last post by:
I have a lookup table from which I want to categorize various bands of customer net income. Some of the income is positive, some is negative. The bands vary in size (ie, <500, -200 to 0, 100 to...
4
by: basstwo | last post by:
I have a field with a serial number in it. I want to use Mid to extract the 4th and 5th characters, use them to lookup a value on a small lookup table, and use the info from that table to fill in...
8
by: Christine Henderson | last post by:
I have a problem using the above function in the following simplified circumstance: In the lookup table called "Klms Travelled" I have 3 fields, eg: Receiver Name Receiver Suburb ...
6
by: WWH | last post by:
New to Access and have what should be a simple problem. Have two tables... 1. first table has description of herbs and Chapter+Section number (ie 2.3 - decimal) 2. second table has same...
3
by: mmorgan1240 | last post by:
I have a form that I am trying to update. I would like to have a field populated by another table (State_laws) based on the value of another field on the form. I have a field called "state". When...
1
by: BobM | last post by:
i read the thread entitled "Convert Field Value String to Actual Field in Expression" It appeared that the final solutions got moore complex not less complex MY PROBLEM IS: 1. get a value from...
7
by: samdev | last post by:
I have set up a table with a few fields that are set to required....all work fine except the fields that are Lookup from another table. What am I forgetting to set? Thanks!!
2
by: dlevene | last post by:
Hi - newbie here, be gentle. In Access 2003, I've created a report (based on a query) to produce mailing labels for all records where = "Community". is a combo-box field with the values coming from...
1
by: Constantine AI | last post by:
Hi i am trying to get User input if data does not exist within a DLOOKUP table. I have gotten it to work for one record but not multiple, i have tried to incorporate my code into a loop procedure but...
15
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.