ASP Replace function not working - ms-access

<%
Dim objRs
Dim conn
Dim strSearchString
strSearchString = Request.Form("name")
Set objRs = Server.CreateObject("ADODB.recordset")
objRs.CursorLocation = 3
set conn = Server.CreateObject("ADODB.Connection")
conn.open "Data Source=" & Server.Mappath("../db/certs.mdb") & ";Provider=Microsoft.Jet.OLEDB.4.0;"
'replace apostrophe in name to avoid issues
strSearchString = Replace(strSearchString.tostring, "'", "''")
'Sql Query
sql = "Select * FROM [cert] Where [name] like '" & strSearchString & "'"
'open connection
ObjRs.Open sql,conn
'setup the table
with response
.write "<table border=1 width=100% cellspacing=0 cellpadding=0 class=CustomerTable>" & vbcrlf
.write "<tr>"
.write "<th class=AccName colspan=9><div align=center>" & strSearchString & "'s Certifications</div></th></tr>"
.write "<tr>" & vbcrlf
.write "<th class=AccName>Name</th>"
.write "<th class=AccName>Certification</th>"
.write "<th class=AccName>Date Completed</th>"
.write "<th class=AccName>Industry</th>"
.write "<th class=AccName colspan=2>Certification #</th>"
.write "<th class=AccName>Vendor</th>"
.write "<th class=AccName>Date Expires</th>"
.write "<th class=AccName><a href='viewall_sortTechnology.asp'>Technology</a></th>"
.write "</tr>" & vbcrlf
End with
%>
I'm attempting to use the replace function in order to avoid issues with names containing apostrophes. It seems that this isn't working as when I run the page, the output displays only "O's Certifications" instead of "O'Brien's Certifications".
I should note that the code works as expected for any person without an apostrophe in their name.
The back-end database is MS Access.
I'm fairly new to asp, so any assistance here is greatly appreciated.

The safer, better way to do this is to use parameterized queries.
See: Parameterized query in Classic Asp

Related

fixing cell padding via html in a access database

I currently have a code in a database that sends an email with a table
The table currently is not formatted it correctly and Im unable to apply cell padding. Any ideas?
enter image description here
Here is the code accompanying it
Function exporthtml()
Dim strline, strHTML, strMsg
Dim Cnt As String
Dim strFilt As String
Dim ACname As String
Dim filt As String
Dim strCC As String
Cnt = DCount("[PATS Action ID]", "tblPAT", "Bureau='" & Form_frmMainPATS.cboBur.Value & "'")
ACname = DLookup("FIRSTNAME", "qryAC", "Bureau='" & Form_frmMainPATS.txtFull.Value & "'")
strFilt = DLookup("WORKEMAIL", "qryAC", "Bureau='" & Form_frmMainPATS.txtFull.Value & "'")
Dim OL As Outlook.Application
Set OL = New Outlook.Application
Set MyItem = Outlook.Application.CreateItem(olMailItem)
Report_rptCurrentPATS.Filter = "Bureau='" & Form_frmMainPATS.cboBur.Value & "'"
Report_rptCurrentPATS.FilterOn = True
DoCmd.OutputTo acOutputReport, "rptCurrentPATS", acFormatHTML, "R:\Epi- Admin\Administrative Collaboration\Admin Review Meetings\Weekly Administrative Reports\Working Documents\Bureau Status Report Updates\TEST.html"
Open "R:\Epi-Admin\Administrative Collaboration\Admin Review Meetings\Weekly Administrative Reports\Working Documents\Bureau Status Report Updates\TEST.html" For Input As 1
Do While Not EOF(1)
Input #1, strline
strHTML = strHTML & strline
Loop
Close 1
If Left(OL.Version, 2) = "10" Then
MyItem.BodyFormat = olFormatHTML
End If
MyItem.To = strFilt
MyItem.Subject = "Updated PATS Status Report as of " & Date - 1
MyItem.HTMLBody = "<BODY bgcolor='#E6E6FA'>" & "<img src='R:\Epi-Admin\Fiscal Management and Reporting Unit\Database\PS Database\logo.png' ALT='Banner'" & "<p>" & "<FONT color = '#000000'>" & "Dear " & ACname & "," & "<br/>" & "<br/>" & Form_frmMainPATS.cboBur.Value & " currently has " & Cnt & " pending personnel actions." & "</p>" & "<p>" & "Please see the report below:" & "<br/>" & "<BODY>" & "<table border= '1'>" & "<bgcolor=#ffffff; cellspacing=10; table-layout: fixed; >" & "<table header= '1' bgcolor='#fffff'>" & strHTML & "</table>" & "</br>" & "<br/>" & "</br>" & "</br>" & "<p> If you have any questions, please contact your desingated Personnel Coordinator"
MyItem.Display
End Function
Any help would be appreciated
Expanding on my comment from above, you can try to see if something like this works or gets you in the right direction (not tested):
Dim strCell() as string
Do While Not EOF(1)
Input #1, strline
strCell() = Split(strline, vbTab) 'Replace vbTab with deliminator if needed
dim i as integer
for i = 0 to UBound(strCell)
strline = "<td>" & strCell(i) & "</td>"
next
strHTML = strHTML & "<tr>" & strline & "</tr>"
Loop
Close 1

how to use Unordered HTML List in excel vba code?

I have been trying to send a email via excel and use html in the message body but it seems excel does not reconize de <\li>. I have the microsoft html Oject library added.
Sub send()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "dupma4"
'.CC = "Patrick.Blouin#mern.gouv.qc.ca;Veronic.Cinq-Mars#mern.gouv.qc.ca"
.BCC = ""
.Subject = "Ajouts d'adresse | [" & mun & " " & ville & "] | [" & Format(Now(), "yyyy-MM-dd") & "]"
.HTMLBody = "Bonjour," & "<br>" & "<br>" _
& "<ul>" & "<li> & message1 & "</li>" & "<li>" & message2 _
& "</li>" & "</ul>"
'.Send
End With
End Sub
You're missing an ending quotation mark (") for your first li. So it should be as follows...
.HTMLBody = "Bonjour," & "<br>" & "<br>" _
& "<ul>" & "<li>" & message1 & "</li>" & "<li>" & message2 _
& "</li>" & "</ul>"

Adding If-Then statement to email text

I'm trying to add an If-Then statement to my VBA in order to create two different email texts based on whether a specific field is populated in a table.
If no data is in the [VendorID/UIN] field in the t1stNoticeEmails table, I'd like this text:
"Please provide a current remit-to address as soon as possible so we can resend the check(s) to the intended recipient(s). The funds from this check will remain as a charge against the FOAPALs utilized in the transaction until this matter is resolved."
If there is data in the [VendorID/UIN] field in the t1stNoticeEmails table, I'd like this additional text:
"In addition, the Vendor ID associated with this transaction may need to be updated. Please contact Vendor Maintenance."
Here's the code:
Sub FirstEmail_IncorrectAddress_ReviewVBA()
Dim rst As DAO.Recordset
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim rst2 As DAO.Recordset
Dim strTableBeg As String
Dim strTableBody As String
Dim strTableEnd As String
Dim strFntNormal As String
Dim strTableHeader As String
Dim strFntEnd As String
Dim CheckNum As String
Dim NameOfRecipient As String
Dim StrSQL1 As String
Dim NameSpaceOutlook As Outlook.Namespace
gPARAttachment = "S:\...."
'SEND FIRST NOTICE EMAILS'
'------------------'
Set rst2 = CurrentDb.OpenRecordset("select distinct ContactEmails from t1stNoticeEmails WHERE CheckReturnReason = 'IncorrectAddress'")
If rst2.RecordCount = 0 Then 'checks if recordset returns any records and continues if records found and exits if no records found
Exit Sub
End If
rst2.MoveFirst
'Create e-mail item
Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)
'Do Until rst2.EOF
Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)
'Define format for output
strTableBeg = "<table border=1 cellpadding=3 cellspacing=0>"
strTableEnd = "</table>"
strTableHeader = "<font size=3 face='Calibri'><b>" & _
"<tr bgcolor=#4DB84D>" & _
td("CheckNumber") & _
td("PayeeName") & _
td("VendorID") & _
td("DocNo / ERNo / PONo") & _
td("Amount") & _
td("CheckDate") & _
td("OriginalCheckAddress1") & _
td("OriginalCheckAddress2") & _
td("OriginalCheckCity") & _
td("OriginalCheckState") & _
td("OriginalCheckZip") & _
"</tr></b></font>"
strFntNormal = "<font color=black face='Calibri' size=3>"
strFntEnd = "</font>"
Set rst = CurrentDb.OpenRecordset("SELECT * FROM t1stNoticeEmails where ContactEmails='" & rst2!ContactEmails & "' AND CheckReturnReason = 'IncorrectAddress' Order by FullName asc")
If rst.RecordCount = 0 Then
rst2.Close
Set rst2 = Nothing
Exit Sub
End If
rst.MoveFirst
NameOfRecipient = rst!FullName
CheckNum = rst!CheckNumber
'Build HTML Output for the DataSet
strTableBody = strTableBeg & strFntNormal & strTableHeader
Do Until rst.EOF
strTableBody = _
strTableBody & _
"<tr>" & _
"<TD nowrap>" & rst!CheckNumber & "</TD>" & _
"<TD nowrap>" & rst!FullName & "</TD>" & _
"<TD nowrap>" & rst![VendorID/UIN] & "</TD>" & _
"<TD nowrap>" & rst![DocNo / ERNo / PONo] & "</TD>" & _
"<TD align='right' nowrap>" & Format(rst!AmountDue, "currency") & "</TD>" & _
"<TD nowrap>" & rst!OriginalCheckDate & "</TD>" & _
"<TD align='left' nowrap>" & rst!OriginalCheckAddress1 & "</TD>" & _
"<TD align='left' nowrap>" & rst!OriginalCheckAddress2 & "</TD>" & _
"<TD align='left' nowrap>" & rst!OriginalCheckCity & "</TD>" & _
"<TD align='left' nowrap>" & rst!OriginalCheckState & "</TD>" & _
"<TD align='left' nowrap>" & rst!OriginalCheckZip & "</TD>" & _
"</tr>"
rst.MoveNext
Loop
'rst.MoveFirst
strTableBody = strTableBody & strFntEnd & strTableEnd
'rst.Close
'Set rst2 = CurrentDb.OpenRecordset("select distinct ch_email from t_TCard_CH_Email")
'rst2.MoveFirst
Call CaptureIABodyText
With objMail
'Set body format to HTML
.To = rst2!ContactEmails
.BCC = gIAEmailBCC
.Subject = gIAEmailSubject & " - Check# " & CheckNum & " - " & NameOfRecipient
.BodyFormat = olFormatHTML
.HTMLBody = .HTMLBody & gIABodyText
.HTMLBody = .HTMLBody & "<HTML><BODY>" & strFntNormal & strTableBody & " </BODY></HTML>"
.HTMLBody = .HTMLBody & gIABodySig
.SentOnBehalfOfName = ""
.Display
'.Send
End With
rst2.MoveNext
'Loop
rst.Close
Set rst = Nothing
rst2.Close
Set rst2 = Nothing
End Sub
This will give you an additional variable sAdditionalText that you can concatenate to your main string wherever you want:
Dim sAdditionalText As String
If IsNull(rst![VendorID/UIN]) Then
sAdditionalText = "Please provide a current remit-to address as soon as possible so we can resend the check(s) to the intended recipient(s). The funds from this check will remain as a charge against the FOAPALs utilized in the transaction until this matter is resolved."
Else
sAdditionalText = "In addition, the Vendor ID associated with this transaction may need to be updated. Please contact Vendor Maintenance."
End If

left align a cell contents in html table

I am sending an e-mail from Excel using Outlook. I am sending the message as an html message. The message sends but not in the format I expect. The headers are fine but the cells below do not left align as I expect.
How do I get the cells below the header to be left aligned? I thought by using the align attribute it should be fine?
My code
Private Function CreateHTMLMsg() As String
Dim msg As String
Dim colourMkt As String
Dim colourBid As String
Dim colourAsk As String
Dim i As Integer
msg = "<table style='font-size: 12pt;'><tr></tr><tr><th align='left'>Fund</th><th> </th>" & _
"<th align='left'>Mkt Spread</th><th> </th>" & _
"<th align='left'>Bid Spread</th><th> </th>" & _
"<th align='left'>Ask Spread</th><th> </th></tr>"
For i = 1 To UBound(pBreaches)
If pBreaches(i).SendEmail = True Then
If pBreaches(i).BreachedMkt = True Then
colourMkt = "yellow"
Else
colourMkt = "transparent"
End If
If pBreaches(i).BreachedBid = True Then
colourBid = "yellow"
Else
colourBid = "transparent"
End If
If pBreaches(i).BreachedAsk = True Then
colourAsk = "yellow"
Else
colourAsk = "transparent"
End If
msg = msg & "<tr style='font-size: 10pt;'><td>" & pBreaches(i).Fund & "</td><td> </td><td>" & _
"<td align='left' style='background-color:" & colourMkt & "'>" & pBreaches(i).SpreadMkt & "</td><td> </td><td>" & _
"<td align='left' style='background-color:" & colourBid & "'>" & pBreaches(i).SpreadBid & "</td><td> </td><td>" & _
"<td align='left' style='background-color:" & colourAsk & "'>" & pBreaches(i).SpreadAsk & "</td><td> </td><td></tr>"
End If
Next i
CreateHTMLMsg = msg & "</table>"
End Function
Try with :
style="float: left;" (HTML)
float: left; (CSS)
Here is more infos about HTML table and CSS about it : Complete Guide to the Table element

Alternating Colors of Rows with HTML

I am currently writing code in VBA to automate a process that sends out an e-mail that contains a table with information generated by a query in an Access database. I am using HTML to format the table in that e-mail, and I need the colors of the rows in that table to alternate colors (odd rows: #ccffcc; even rows: #ffffff), but I cannot seem to figure it out. I have tried to use the child selector, but I cannot see to figure out to get that to work in here. I do not have much experience or knowledge related to CSS or HTML, so I very well could have been using the child selector incorrectly.
Here is what I currently have:
Bodytext2 = "<html>" & _
"<body>" & _
"<TABLE BORDER=0 CELLpadding=0 style='font-family:Arial; font-size:12px'>" & _
"<TBODY>" & _
"<TH bgcolor='#dcdcdc'> Field1 </TH>" & _
"<TH bgcolor='#dcdcdc'> Field2 </TH>" & _
"<TH bgcolor='#dcdcdc'> Field3 </TH>"
'Creates the table
Set rst = mydb.OpenRecordset("Query In Access")
Do Until rst.EOF
Bodytext2 = Bodytext2 & _
"<TR ALIGN=CENTER VALIGN=MIDDLE>" & _
"<TD> " & rst![Field1] & _
"<TD> " & rst![Field2] & _
"<TD> " & rst![Field3]
rst.MoveNext
Loop
rst.Close
Bodytext2 = Bodytext2 & "</table>"
This code produces the correct table with the correct information. however, I am not sure where to add in the code to change the colors of the table's rows, or how to even write the code to do that. My guess so far is that it would be in the "TR Align=center valign=middle" portion, but that is just my guess.
I have looked a lot of other answers on here, but I think that my lack of knowledge in this field is making it difficult for me to determine what I actually need and where it needs to go. So, if there are helpful answers to similar questions that y'all could direct me to, I would greatly appreciate that too.
Thank You!
Create a counter variable before you go into your loop that will let you keep track of your row number, like this:
i = 1
Do Until rst.EOF
If i Mod 2 = 0 Then
Bodytext2 = Bodytext2 & "<TR ALIGN=CENTER VALIGN=MIDDLE BGCOLOR='#ffffff'>"
Else
Bodytext2 = Bodytext2 & "<TR ALIGN=CENTER VALIGN=MIDDLE BGCOLOR='#ccffcc'>"
End If
Bodytext2 = Bodytext2 & _
"<TD> " & rst![Field1] & _
"<TD> " & rst![Field2] & _
"<TD> " & rst![Field3]
rst.MoveNext
i = i + 1
Loop
My apologies for any syntax errors. My VBA is a little rusty.