473,386 Members | 1,819 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,386 software developers and data experts.

Send an Email with parameters from two different tables

93
I am trying to generate an email that is gathering information from two different tables. I keep getting an error message that it can not find my CustomerNo. Does anyone have any ideas?
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdEmail_Click()
  3.     Dim CustomerNo As Parameter
  4.     Dim ClientID As Parameter
  5.  
  6. On Error GoTo Err_Email_Click
  7.  
  8.     stEmailTo = DLookup("[CustomerMailingsEMail]", "[Customer]", "[CustomerNo] = '" & Me![ CustomerNo] & ";" & " " _
  9.     And DLookup("[ReportMailingCC]", "[Clients]", "[ClientID] = '" & Me![ClientID]) & "'")
  10.     DoCmd.SendObject acReport, stDocName, acFormatRTF, stEmailTo, , , _
  11.     "Orders" & "," & " " & DLookup("[Customer Name]", "[Customer]", "[CustomerNo] = '" & Me![CustomerNo] & "'") & "," & " " & _
  12.     DLookup("[Physical City]", "[Customer]", "[ CustomerNo] = '" & Me![ Customer No] & "'") & "," & " " & _
  13.     DLookup("[Physical State]", "[ Customer]", "[ CustomerNo] = '" & Me![ CustomerNo] & "'") & "," & " " & _
  14.     DLookup("[Physical Country]", "[ Customer]", "[ CustomerNo] = '" & Me![ CustomerNo] & "'") & " " & " CustomerNo" & " " & Me![ CustomerNo], _
  15.     DLookup("[ReportMailingInstructions]", "[Clients]", "[ClientID] = '" & Me![ClientID]) _
  16.     & vbCr & DLookup("[ReportMailingEmailText]", "[Clients]", "[ClientID] = '" & Me![ClientID])
  17.  
  18.  
  19. Exit_Email_Click:
  20.     Exit Sub
  21.  
  22. Err_Email_Click:
  23.     MsgBox Err.Description
  24.     Resume Exit_Email_Click
  25.  
  26. End Sub
  27.  
  28.  
Jun 4 '08 #1
7 1668
Stewart Ross
2,545 Expert Mod 2GB
If you look at lines 7 onwards in your post you will see that the field and control names vary. Many have spaces at the start of the name (e.g. [ Customer] when [Customer] would be expected) and some change from no space between words [CustomerNo] to one space
[Customer No].

I can't tell which ones are correct - but some of them cannot be right

-Stewart
Jun 4 '08 #2
clloyd
93
Thanks. I fixed those errors but it still doesn't find the Customer Number. I believe it is in the code calling on the two different tables for all the information needed. Here is my revised code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdEmail_Click()
  3. Dim CustomerNo As Parameter
  4. Dim ClientID As Parameter
  5.  
  6. On Error GoTo Err_Email_Click
  7.  
  8. stEmailTo = DLookup("[CustomerMailingsEMail]", "[Customer]", "[CustomerNo] = '" & Me![CustomerNo] & ";" & " " _
  9. And DLookup("[ReportMailingCC]", "[Clients]", "[ClientID] = '" & Me![ClientID]) & "'")
  10. DoCmd.SendObject acReport, stDocName, acFormatRTF, stEmailTo, , , _
  11. "Orders" & "," & " " & DLookup("[CustomerName]", "[Customer]", "[CustomerNo] = '" & Me![CustomerNo] & "'") & "," & " " & _
  12. DLookup("[Physical City]", "[Customer]", "[CustomerNo] = '" & Me![CustomerNo] & "'") & "," & " " & _
  13. DLookup("[Physical State]", "[Customer]", "[CustomerNo] = '" & Me![CustomerNo] & "'") & "," & " " & _
  14. DLookup("[Physical Country]", "[Customer]", "[CustomerNo] = '" & Me![CustomerNo] & "'") & " " & " CustomerNo" & " " & Me![CustomerNo], _
  15. DLookup("[ReportMailingInstructions]", "[Clients]", "[ClientID] = '" & Me![ClientID]) _
  16. & vbCr & DLookup("[ReportMailingEmailText]", "[Clients]", "[ClientID] = '" & Me![ClientID])
  17.  
  18.  
  19. Exit_Email_Click:
  20. Exit Sub
  21.  
  22. Err_Email_Click:
  23. MsgBox Err.Description
  24. Resume Exit_Email_Click
  25.  
  26. End Sub
  27.  
  28.  
Jun 4 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi again. In line 7 of post 3 you use a semicolon ";" instead of a single quote "'" as the delimiter immediately after referring to your Customer No control. Change it to a single quote and the reference to the Customer No should be correctly recognised.

You are also missing some closing single quotes from your DLookups - see lines 14 and 15 for examples where there is an opening quote but no closing quote used (at the end of the statement).

I cannot untangle the nesting of the Dlookups, but some of them do not look closed to me - I can only say that I think the set of Dlookups is not quite right (look at line 13, where there is a reference to Customer No outside the Lookup but with no comparator).

Given the number of typos that have occurred I would ask you to check carefully that all DLookups are opened and closed correctly, and where they are nested (if that is the intention) that the nesting is correctly done, or you will never sort out the errors that arise. I would also check and recheck that there is a closing quote for every opening quote, and that comparators are used when you are actually comparing values (cf line 13 and the lack of a comparator).

As a stylistic matter I note that you add spaces onto the string like this:
Expand|Select|Wrap|Line Numbers
  1. "previous part of string" & " " & "next part of string" & " "
I would suggest for clarity declaring a string constant and using it as follows:
Expand|Select|Wrap|Line Numbers
  1. Const SingleSpace = " "
  2. "previous part of string" & SingleSpace & "next part of string" & SingleSpace
There is nothing wrong at all with using discrete space strings the way you do at present, but declaring them explicitly makes reading the code (and hence maintaining it in future) easier.

-Stewart
Jun 4 '08 #4
clloyd
93
I am sorry. I am new at this. I don't understand what you
Jun 4 '08 #5
clloyd
93
Ignore my last message I hit the button to soon. I didn't understand something but figured it out. OK I reworked it and I think I am almost there. See if this makes better sence. I decided to attach the report because I have another program that I do this for and it works fine. The problem I truly believe with this one is it is pulling in information from two different tables as I mentioned before. Here is the reworked code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdEmail_Click()
  3. On Error GoTo Err_Email_Click
  4.  
  5.     Dim stDocName As String
  6.     Dim stLinkCriteria As String
  7.  
  8.     stDocName = "rptReportDistribution"
  9.     stEmailTo = DLookup("[CustomerMailingsEMail]", "[Customer]", "[CustomerNo] = '" & Me![CustomerNo] & "'")
  10.     'stLinkCriteria = ("[CustomerNo]=" & "'" & ("[CustomerNo]=Reports![rptReportDistribution]![CustomerNo]" AND ""[ClientID]=" & "'" & ("[ClientID]=Reports![rptReportDistribution]![ClientID]")& "'"
  11.     DoCmd.SendObject acReport, stDocName, acFormatRTF, stEmailTo, DLookup("[ReportMailingCC]", "[Clients]", "[ClientID] = '" & Me![ClientID]), , _
  12.     "Loss Prevention Survey" & "," & " " & DLookup("[Loc Name]&','&' '& 'CustomerNo.' & ' ' & [CustomerNo]&','&' '& [Physical City]&','&' '& [Physical State]&','&' '& [Physical Country]", "[Customer]", "[CustomerNo]=Reports![rptReportDistribution]![CustomerNo]"), _
  13.     "Report Mailing Instructions:" & "," & " " & DLookup("[ReportMailingInstructions]", "[Clients]", "[ClientID] = '" & Me![ClientID] & "'") _
  14.     & vbCr & DLookup("[ReportMailingEmailText]", "[Clients]", "[ClientID] = '" & Me![ClientID])
  15.  
  16.  
  17. Exit_Email_Click:
  18.     Exit Sub
  19.  
  20. Err_Email_Click:
  21.     MsgBox Err.Description
  22.     Resume Exit_Email_Click
  23.  
  24. End Sub
  25.  
  26.  
Jun 4 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi. I am not sure what you mean when you mention "pulling in information from two different tables". Dlookup is intended to look up a value from any table or query you require. However, I notice you are referring to controls on a report within your DLookup - this will not work for you. Firstly, it could only work at all if the report is open at the time. Secondly, including the name of the control as part of the string will lead to problems interpreting what you want to lookup - the norm is to include the current value of such a control within the Dlookup (as you are doing for the Customer No value in other DLookups).

I am unable to comment further on whether or not what you are trying to do is sound, because I do not and cannot know the details you know of what you are trying to achieve. What I can advise is as follows:

* DLookup can be used to return values from tables or queries, just as you are doing
* If in the DLookup criteria you include comparisons of fields to controls use a reference to the value of the control, not its name (see line 11 post 6 for an example of including the name of a report control as part of the criteria string)

That is, for numeric values use
Expand|Select|Wrap|Line Numbers
  1. DLookup("somevalue", "sometable", "somefield = " & acontrolname)
instead of
Expand|Select|Wrap|Line Numbers
  1. DLookup("somevalue", "sometable", "somefield = acontrolname")
or for strings
Expand|Select|Wrap|Line Numbers
  1. DLookup("somevalue", "sometable", "somefield = '" & acontrolname & "'")
instead of
Expand|Select|Wrap|Line Numbers
  1. DLookup("somevalue", "sometable", "somefield = acontrolname")
* If the value you are referring to is on another form or report that form or report must be open at the time you refer to it. You cannot refer to controls on forms or reports that are not open at the time.

I hope this gives you enough in the way of pointers to solve any remaining issues. I think I have gone as far as is possible in interpreting what could be wrong with your code without having the database in front of me at the time.

-Stewart
Jun 4 '08 #7
clloyd
93
It definatetly does help. Thank you for all your help. I am going to keep plugging away on it.
Jun 5 '08 #8

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

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
40
by: ian | last post by:
Hi, I'm a newbie (oh no I can here you say.... another one...) How can I get Python to send emails using the default windows email client (eg outlook express)? I thought I could just do the...
1
by: Bruce W.1 | last post by:
I'm new to ASP (but not ASP.NET) and I'm trying to setup a simple ASP web form to send an email to me. So I try this code: http://www.library.unr.edu/subjects/guides/mailplay.asp I upload the...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
2
by: a | last post by:
how to send an xml dataset to a Stored Procedure in mssql I have an xml file that I read into a dataset. and I'm trying to use a stored procedure (see SPROC #1 below) that inserts this xml...
3
by: jgscott3 | last post by:
I have a number of queries that require various parameters. However, the parameters will change infrequently, so I do not want the user to have to respond to them every time they run the queries. ...
1
by: chaitanya02 | last post by:
Hi All, Well- this question might have appeared several times on this forum- but would appreciate your reply on this: I have a asp page, where customers login with some username and the pwd,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.