• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • 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, 
                      dbo.tblWorkOrders.DateClosed
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

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

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

--
JimFive
0
 
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.

Thanks,

jim
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JimFiveCommented:
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
  rs.movenext
wend

--
JimFive
0
 
JimFiveCommented:
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.

--
JimFive
0
 
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!
0
 
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 = "http://192.168.142.224/email/sendemail.asp?woid="
    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.Open()
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
	objCDOSYSCon.Fields.Update
	
	Set objCDOSYSMail.Configuration = objCDOSYSCon
	objCDOSYSMail.From = "EMAIL ADDRESS"
	objCDOSYSMail.To = "EMAIL ADDRESS"
	objCDOSYSMail.Subject = strSubject
	objCDOSYSMail.HTMLBody = strBody
	objCDOSYSMail.Send
	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)
	rs.movenext
loop
 
Response.Redirect("success.htm")
 
%>

Open in new window

0
 
JimFiveCommented:
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.
--
JimFive
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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