• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

I have an Access Report and would like an ASP page to show the exact same thing

I have an MS Access Project that connects to a SQL backend. In the Access program I have the attached query;

I have created a report that uses this query and I pass a parameter to it to filter the query by Workorder ID. The report works great, it will show the name of the person only once and list the activies on the workorder. This way i see the name once and the list of activities which could be a lot.

When I try to use this query in ASP I get a table that will not group by work order ID. Show the table shows the clients name for each activity ID.

I think the problem is in my JOINS, but am not sure.
SELECT     dbo.tblWorkOrders.ID AS [Work Order ID], dbo.tblCustomer.FirstName AS CFName, dbo.tblCustomer.LastName AS CLName, 
                      dbo.tblCustomer.BusinessName AS CBName, dbo.tblCustomer.DaytimePhone AS CPhone, dbo.tblCustomer.MobilePhone AS CMPhone, 
                      dbo.tblCustomer.Address01 AS CAddress1, dbo.tblCustomer.Address02 AS CAddress2, dbo.tblCustomer.City AS CCity, dbo.tblCustomer.State AS CState, 
                      dbo.tblCustomer.Zip AS CZip, dbo.tblCustomer.EmailAddress AS CEmail, dbo.lstStatus.Status, dbo.lstServiceTypes.ServiceType, 
                      dbo.lstPriority.Priority, dbo.lstComputerManufacturers.ComputerManufacturer, dbo.lstComputerTypes.ComputerType, dbo.tblActivity.ID AS ActID, 
                      dbo.tblTechnician.FirstName AS TFName, dbo.tblActivity.Date AS ActDate, dbo.tblActivity.Time AS ActTime, dbo.tblActivity.Activity, 
FROM         dbo.lstComputerTypes RIGHT OUTER JOIN
                      dbo.tblWorkOrders ON dbo.lstComputerTypes.ID = dbo.tblWorkOrders.ComputerType LEFT OUTER JOIN
                      dbo.tblCustomer ON dbo.tblWorkOrders.CustomerID = dbo.tblCustomer.ID LEFT OUTER JOIN
                      dbo.lstPriority ON dbo.tblWorkOrders.Priority = dbo.lstPriority.ID LEFT OUTER JOIN
                      dbo.lstStatus ON dbo.tblWorkOrders.Status = dbo.lstStatus.ID LEFT OUTER JOIN
                      dbo.lstServiceTypes ON dbo.tblWorkOrders.ServiceType = dbo.lstServiceTypes.ID LEFT OUTER JOIN
                      dbo.lstComputerManufacturers ON dbo.tblWorkOrders.Manufacturer = dbo.lstComputerManufacturers.ID RIGHT OUTER JOIN
                      dbo.tblTechnician RIGHT OUTER JOIN
                      dbo.tblActivity ON dbo.tblTechnician.ID = dbo.tblActivity.TechnicianID ON dbo.tblWorkOrders.ID = dbo.tblActivity.WorkOrderID

Open in new window

  • 4
  • 3
1 Solution
James MurrellProduct SpecialistCommented:
spaces   access on the web table, column names must not have spaces
To limit to a work order you need to add a WHERE clause to the query.

i.e. WHERE tbl.WorkOrders.ID = '12345'

mdefalcoAuthor Commented:
Yeah, what I do for that is this;

In my access application I have a listbox that the user selects which work order he wants to email. When they click on the work order in the listbox it populates a global parameter I have, G_WOID. Then is uses the Follow.Hyperlink code to go to an asp page I have that will run this query and pull the data.

This works real well, but the problem I have is that if there are more than one activity for the workorder, then two emails will send. I want the email to send once per work order with all activities in the body of the email.

I use ASP because I want the email sent without needing an outlook profile to send the email.


A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

I assume that you are looping through the query results to build the email.

If this is the case, then you will need to save the work order ID, check it on each loop, and only start a new email when the ID changes.

Your loops should look something like this:

while not rs.eof()
  if rs(workorderid) <> savedworkorderid then ' New workorder
      Close and send existing mail message
      savedworkorderid = rs(workorderid)
      create new mail message
      fill in workorder info
  end if
  Add line item info to email

Two issues I forgot to mention

1.  Make sure your query is sorted by workorderid (ORDER BY WorkorderID)

2.  The reason the access report is working is because the access report engine is doing all of grouping and looping for you.

mdefalcoAuthor Commented:
Cool, I am  a technician who is always on the road, so I will try this in the next couple days. I think you are correct though, thanks!
mdefalcoAuthor Commented:
Here is my asp code,
My query selects only the work order ID I pass through the URL, I looked at your suggestion, but I can not figure out exactly what I should put in for code. So my main goal is to only send one email, but have the all the activities. I guess I don't know how to group the activities,

Thanks in advance.

Here is the code I use in Access to pass the WOID to the ASP PAge;

    Dim strInput As String
    Dim strWOID As String
    strWOID = Me.List63.Value
    strInput = ""
    strInput = strInput & strWOID
    Application.FollowHyperlink strInput, , True

<!-- #include virtual="email/conn.asp" -->
<% Server.ScriptTimeout =7200%>
Dim strWoID
strWoid = Trim(request("woid"))
Dim strSQL
Dim rs
Dim rs_numRows
strSQL = "SELECT * FROM qryWFP WHERE [Work Order ID] = " & strWOID
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = strCONN
rs.Source = strSQL
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 1
rs_numRows = 0
Function SndEmail(strSubject,strBody)
	Set objCDOSYSMail = Server.CreateObject("CDO.Message")
	Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "x.x.x.x"
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "EMAIL ADDRESS"
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSWORD"
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
	objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
	Set objCDOSYSMail.Configuration = objCDOSYSCon
	objCDOSYSMail.Subject = strSubject
	objCDOSYSMail.HTMLBody = strBody
	Set objCDOSYSMail = Nothing
	Set objCDOSYSCon = Nothing
	End Function
Dim strSubject
Dim strBody
Dim strFullName
	do while not rs.eof
	strFullName = rs("CFName") & " " & rs("CLName")
    strSubject = "Work Order ID " & rs("Work Order ID") & " is Waiting for Payment"	
	strBody = "Name: " & strFullName & vbcrlf
	strBody = strBody & "Business Name: " & rs("CBName") & vbcrlf
	Call SndEmail(strSubject,strBody)

Open in new window

At line 68, you want to move your do while loop to loop around the items that you want to repeat:

Move the do while down to line 73
Change line 74 to be strBody = strBody & "Name: " & strFullName & vbcrlf  <---- this builds the email body
Move line 78 outside of the loop to line 81  <----- This waits to send the email until after all the rows have been processed.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now