Replace() in HTML in code behind (VB.NET) - html

strbody = strbody & "<font face=""Verdana"" size=""1""> <strong>" + Replace(name, "/", "-") + "</strong></font>"
When run the system to send out the email, there is no error in debug but the table interface will haywire because of this Replace().
I've tried as below but still not correct. Please help. Tq
Edit:
Replace(name, "/", "-") is correct syntax to use in code behind, but now I need to put it in html format in code behind for sending email. So I think I miss out some char to add. Like <font face=""Verdana"" , I need to put double "
'strbody = strbody & "<font face=""Verdana"" size=""1""> <strong>" + Replace(name, "" / "", "" - "") + "</strong></font>"

Related

Enclosing the content of object in double quotes in VBA

It probably sounds simple, but I can not find a way out.
I'm trying to create a more or less dynamic json and I need to convert the content of object to a string between double quotes. Something like that :
""" + object + """ gives the following result "object" and the expected result would be "content of object".
Here is my code, will probably be more clear, about what it's about.
Dim jsTest As String
jsTest = """ + CStr(Msg.Subject) + """ + """ + CStr(Msg.Body) + """
Msg.Subject and Msg.Body are objects from Email. I can do that this way(with single quotes):
Dim smry, descrp, jsTest As String
smry = """summary"""
descrp = """description"""
jsTest = "{" + smry + ":" + "'" + CStr(Msg.Subject) + "'" + "," + descrp + ":" + "'" + CStr(Msg.Body) + "'" + "}"
but then I get content of object as String with single quotes and I cant put it in my JSON like so:
{"summary": 'Release 18.20 Produktion', "description": 'Guten Tag Sie erhalten diese Terminanfrage'}
How can I get result like (Note double quotes):
{"summary": "Release 18.20 Produktion", "description": "Guten Tag Sie erhalten diese Terminanfrage"}
If you replace this:
jsTest = "{" + smry + ":" + "'" + CStr(Msg.Subject) + "'"
with
jsTest = "{" + smry + ":" + """" + CStr(Msg.Subject) + """"
and so on, you will get your quotes.

Exporting to CSV dropping off text

I am attempting to export out a concatenated note from a table in a database I'm given and export it out into a CSV file. The below code works getting it to be seen in the Datasheet view. However whenever I export the file to a CSV the Note column is cut off at "Actual Note:" and CnNote_1.CnNote_1_Actual_Notes is not displayed. I'm not sure what could cause this and would like help figuring it out.
One potential thing to consider is that CnNote_1.CnNote_1_Actual_Notes is a long text field while all other fields, except the two date fields, are short text fields. I don't know if that's causing it though.
My only other guess is there a hidden character in the beginning of the Actual Note.
I'd greatly appreciate any insight as to why it might be dropping.
SELECT CnBio.CnBio_Import_ID,
CnBio.CnBio_First_Name,
CnBio.CnBio_Last_Name,
CnBio.CnBio_Org_Name,
CnNote_1.CnNote_1_Type AS [Note Type],
Format(CnNote_1.[CnNote_1_Date], 'yyyy-mm-dd') AS [Date],
Format(CnNote_1.[CnNote_1_DateAdded], 'yyyy-mm-dd') AS [Original Date],
IIf(CnNote_1.CnNote_1_Title <> '', "Title: " & CnNote_1.CnNote_1_Title & " ") & IIf(CnNote_1.CnNote_1_Description <> '', "Description: " & CnNote_1.CnNote_1_Description & " ") & IIf(CnNote_1.CnNote_1_Actual_Notes <> '', "Actual Note: " & replace(replace(CnNote_1.CnNote_1_Actual_Notes, Chr(13), " "), Chr(10), " ")) AS Notes
FROM (Cn LEFT JOIN CnBio ON Cn.CnBio_LINK = CnBio.CnBio_LINK) LEFT JOIN CnNote_1 ON Cn.CnNote_1_LINK = CnNote_1.CnNote_1_LINK
For more information I'm exporting via MS Access's export using the Text File export. It also occures when exporting out using the Excel unless I select "Export out with formatting and layout."
I am not sure if that is the only problem but you are using IIF wrong.
Instead of
IIf(CnNote_1.CnNote_1_Title <> '', "Title: " & CnNote_1.CnNote_1_Title & " ")
Use
IIf(CnNote_1.CnNote_1_Title <> '', "Title: " & CnNote_1.CnNote_1_Title & " ", "")
All of your IIFs are similarly flawed.

Mysql not allowing " ' "

I have a table with 4 columns and update them through excel user form and all are varchar (255). when I try to enter the character ' I get syntax error, mysql doesn't accept it... What am I doing wrong here, do I need to change datatype
Update: I figured that the problem is not with MySQL (obviously :) ) but my code to update the table.
Dim sq As String
sq = "UPDATE sample.`nov-21` SET `Site work being carried out`='" & sitecombo.value & "',`Group`='" & eqgrp.value & "',`Description`='" & desc.value & "',`T Number`='" & tn.value & "', WHERE sample.`nov-21`.`ID`= " & Me.IDnum & ";"
Escape ' with \ or another ': 'O''Malley' or 'O\'Malley'
When you write 'O'Malley', MySQL read string literal 'O' followed by name Malley (which is not recognized) and a ' with no meaning, hence the syntax error.

DSum function in vba

I want to display sum of a column in a textbox when I hit a button. But it is giving me a compile error: "Wrong number of arguements or invalid property assignment"
The below code is implemented in vba.
Here is the code that I used:
Text19 = Nz(DSum("Total_Units", "6_Provincial_SUB", , "[BudgetYear] =" & [Combo5] & " And [Program_Name] ='" & Replace([Combo7], "'", "''") & "'"), 0)
DSum has three parameters. You have four. Drop the extra comma
Text19 = Nz(
DSum(
"Total_Units",
"6_Provincial_SUB", <==== Here I dropped a comma (,)
"[BudgetYear] =" & [Combo5] & " And [Program_Name] ='" &
Replace([Combo7], "'", "''") & "'"
),
0
)
When things like this happen, I try to find the problem by indenting the expression like above in order to find matching braces etc. Without line continuation character "_" this will not work of cause, but it gives you an idea of the structure of the expression.
I have these functions in my library. They help me in the creation of SQL strings
Public Function SqlStr(ByVal s As String) As String
'Input: s="" Returns: NULL
'Input: s="abc" Returns: 'abc'
'Input: s="x'y" Returns: 'x''y'
If s = "" Then
SqlStr = "NULL"
Else
SqlStr = "'" & Replace(s, "'", "''") & "'"
End If
End Function
Function Build(ByVal s As String, ParamArray args()) As String
'Build("FirstName = {0}, LastName = {1}","John","Doe") -->
'"FirstName = John, LastName = Doe".
'"\n" is expanded with vbCrLf.
Dim i As Long
s = Replace(s, "\n", vbCrLf)
For i = 0 To UBound(args)
s = Replace(s, "{" & i & "}", Nz(args(i)))
Next i
Build = s
End Function
By using them, your SQL would be constructed like this
sql = Build("[BudgetYear] = {0} AND [Program_Name] = {1}", _
Combo5, SqlStr(Combo7))
You have a comma too many after the domain parameter:
"6_Provincial_SUB", ,
That would make the space the criteria parameter, and the actual criteria an unknown fourth parameter.

Textbox "Like" Search

I have a form that I want to search for anything containing what is entered into a textbox. Right now the search only picks up data that matches exactly (ie MDD), but I want it to capture anything containing the searched item automatically (ie *MDD*)
Ideally I would like a user to enter what they are searching for and get anything that contains that search.
The code I wrote (that partially works) is:
`
If Me.tbIni = "" Or IsNull(Me.tbIni) Then
stCriteria = ""
Else
If InStr(1, Me.tbIni, "LIKE ") Then
stCriteria = "CURQCDB.DT_ini '" & Me.tbIni & "'"
Else
stCriteria = "CURQCDB.DT_ini = '" & Me.tbIni & "'"
Help would be much appreciated.
Just search for *MDD* instead of MDD
Try the following instead. I also took the liberty of sanitizing the input a bit so that it properly handles double and single quotes:
If Me.tbIni = "" Or IsNull(Me.tbIni) Then
stCriteria = ""
Else
stCriteria = "CURQCDB.DT_ini LIKE ""*" & Replace(Me.tbIni, """", """""") & "*"""
End If