I have a database we use for order tracking. I collect information such as the vendor we purchased from as well as tracking information from each vendor for each order. Sometime the orders require multiple vendors and multiple tracking numbers. What I would like is a button to send all the tracking numbers for an order to the customers email.
this is what I have so far: - Private Sub Command9_Click()
-
'Send the E-Mail
-
-
Dim oApp As Outlook.Application
-
Dim oMail As MailItem
-
Dim Subjectline As String
-
Dim emailaddr As String
-
Dim SC As String
-
Dim PO As String
-
Dim SalesC As String
-
PO = Forms![Orders].[PO_NUM]
-
SC = DLookup("SalesChannel", "orders", "PO_NUM ='" & PO & "'")
-
emailaddr = DLookup("Cust_EMAIL", "orders", "PO_NUM ='" & PO & "'")
-
If SC = "1" Then
-
SalesC = "DoD EMALL"
-
Else
-
If SC = "2" Then
-
SalesC = "GSA Advantage"
-
Else
-
SalesC = ""
-
End If
-
End If
-
-
Subjectline = "Tracking Inforamtion for your " & SalesC & " Order " & PO
-
Set oApp = CreateObject("Outlook.application")
-
-
Dim MyBodyText As String
-
-
MyBodyText = "QUERY RESULTS SOMEHOW"
-
-
-
Set oMail = oApp.CreateItem(olMailItem)
-
oMail.Body = MyBodyText
-
oMail.Subject = Subjectline
-
oMail.To = emailaddr
-
'oMail.Send
-
oMail.Display
-
Set oMail = Nothing
-
Set oApp = Nothing
-
-
End Sub
I just need to know how to run the following sql statement - SELECT ShippingAndDelivery.TrackingReceived, ShippingAndDelivery.TrackingNumber, ShippingAndDelivery.ShipMethod
-
FROM Orders INNER JOIN ShippingAndDelivery ON Orders.PO_NUM = ShippingAndDelivery.PONbr
-
WHERE (((Orders.PO_NUM)="MOMS00006806531"));
the PO_NUM will come from the form
Any help would be tremendous!
3 1577 zmbd 5,501
Expert Mod 4TB
Does your query work?
That is to say, if you set it up as a normal query does it return the information you desire?
If it does, then you have several ways of sending this as an attacment using the docmd.sendobject or you can build the message text by opening the query as a recordset within the VBA code and looping thru the records to build the message string, or thru even more advanced automation should you be using Outlook you could insert a table and then populate the table with the recordset results.
The query does work as I want it to and I an trying to build the message body as a record set right now. Im not after pretty - only functional at this moment. Plus most of the people I need to email only receive emails in text mode so a table would be not as effective. Can you point me to the correct recordset command to get what I need. I have made a little progress on the code: - Dim rs As DAO.Recordset
-
Dim SQL As String
-
-
SQL = "SELECT ShippingAndDelivery.TrackingReceived, " & _
-
"ShippingAndDelivery.TrackingNumber, ShippingAndDelivery.ShipMethod " & _
-
"FROM Orders INNER JOIN ShippingAndDelivery ON Orders.PO_NUM = ShippingAndDelivery.PONbr" & _
-
"WHERE (((Orders.PO_NUM)='" & PO & "'"
-
-
Set rs = CurrentDb.OpenRecordset(SQL)
-
-
'Check to see if the recordset actually contains rows
-
If Not (rs.EOF And rs.BOF) Then
-
rs.MoveFirst 'Unnecessary in this case, but still a good habit
-
Do Until rs.EOF = True
-
-
rs.someCommand to get the complete row
-
there are 3 fields in the output
-
-
MyBodyText = "QUERY RESULTS SOMEHOW"
-
-
rs.MoveNext
-
Loop
-
Else
-
MsgBox "There are no records in the recordset."
-
End If
-
-
MsgBox "Finished looping through records."
-
-
rs.Close 'Close the recordset
-
Set rs = Nothing 'Clean up
Thank you for your reply and assistance!
zmbd 5,501
Expert Mod 4TB
It is very importaint that you properly format posted script, be it SQL, VBA, etc... or formated text (ie table) using the [CODE/] button in the format toolbar. It helps keep things like my enterprise AV from tripping malware warnings and it gives us a way to easily reference lines of code etc within your posts.
Rabbit has kindly done that for you in your last post (Thank You Rabbit (^_^) )
Starting on Line16:
Sorry to say there is no single command to pull the entire record at once (well there is; however, it pulls to multi-dimensional array so you end up looping.
actuall there are a few other things... I'll fix some here and then leave the rest for you to code... - 'This is air code... you need to finsh.
-
Sub bytes_957268()
-
Dim zDB As DAO.Database
-
Dim zHoldString As String
-
Dim zMessage As String
-
Dim rs As DAO.Recordset
-
Dim SQL As String
-
'
-
'>In the SQL You have an undeclared variable
-
Dim PO As String
-
'
-
'>Error traps can be your friend
-
On Error GoTo zerr
-
'.
-
'SQL = "SELECT ShippingAndDelivery.TrackingReceived, " & _
-
"ShippingAndDelivery.TrackingNumber, ShippingAndDelivery.ShipMethod " & _
-
"FROM Orders INNER JOIN ShippingAndDelivery ON Orders.PO_NUM = ShippingAndDelivery.PONbr" & _
-
"WHERE (((Orders.PO_NUM)='" & PO & "'"
-
'
-
Set zDB = CurrentDb()
-
Set rs = zDB.OpenRecordset(Name:=SQL, Type:=adOpenDynamic)
-
-
'Check to see if the recordset actually contains rows
-
'I don't depend on the EOF/BOF thing.... if there's even a single record then the count isn't zero.
-
'If Not (rs.EOF And rs.BOF) Then
-
If rs.RecordCount > 0 Then
-
rs.MoveFirst 'Unnecessary in this case, but still a good habit
-
'>I wouldn't bet on this being unnecessary
-
With rs
-
Do
-
'rs.someCommand to get the complete row
-
' - getrows method; however, it really doesn't help you here.
-
'instead add the value of each field in the SQL:
-
'
-
zHoldString = !.TrackingReceived, & "," & '.... finish coding here
-
zMessage = zMessage & zHoldString
-
.MoveNext
-
If Not .EOF Then zMessage = zMessage & Chr(10) & Chr(13)
-
Loop Until .EOF
-
End With
-
Else
-
MsgBox "There are no records in the recordset."
-
End If
-
MsgBox Prompt:=zMessage, Title:="Finished looping through records."
-
ZCleanUp:
-
rs.Close
-
If Not rs Is Nothing Then Set rs = Nothing
-
If Not zDB Is Nothing Then Set zDB = Nothing
-
Exit Sub
-
zerr:
-
MsgBox Err.Number & vbCrLf & Err.description
-
Stop
-
Resume ZCleanUp
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian |
last post by:
Hello,
Basically, I'm running a query on a form's activation, and I'd like to
have the results of the query be placed into other fields on the same
form automatically.
Does anybody know how...
|
by: Rob |
last post by:
I doubt this is the best way to do it, but what I came up
with was to hide the XML in an HTML Comment then edit the
file deleting the HTML stuff and keep the XML results. If
anyone has a better...
|
by: ljungers |
last post by:
Hi and I hope that someone may have an answer for this, or an example of what I need to do. I have a Access database that a clerk will be entering a Order Number or Client Name or a Client City in a...
|
by: fcolon75 |
last post by:
I'm an experienced Access user, but very new to coding VBA in Access.
I'd like to do the following:
1) Develop a basic query in the query designer.
2) Call that query from a VBA script
3)...
|
by: Kelii |
last post by:
I've been trying to get this piece to work for a few hours, but have
given up. I hope someone out there can help, I think the issue is
relatively straightforward, but being a novice, I'm stumped....
|
by: Himmel |
last post by:
Hello!
The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of...
|
by: veaux |
last post by:
Might not have explained this correctly in subject, but query results
look like below:
Name ID Phone
Bill 001 123
Bill 001 234
Bill 001 ...
|
by: aaronkm |
last post by:
Hello thescripts and well met.
I've recently been handed a new duty and have the joy of 'crash coursing' MS Access.
Things are working well but I've ran into a problem that I can't seem to find...
|
by: igor221189 |
last post by:
Hello everyone.
I have Access 2000 database which holds student records in the school.It stores subject grades for each student.In the 'Student Grade Form', I would like to search student surname...
|
by: Dave Mallett |
last post by:
very new to Access. Trying to export query results via macro and transfertext, but keep getting error message stating "Microsoft Jet Engine cannot find the object 'HRQ-DM_Prd1_qtr.txt'. Make sure...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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: 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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
| |