On a command button, how to fix an export a fixed file format? Compile error: Syntax error - button

I have this VBA code, when I try to run it, it gives me "Compile error: Syntax error" as can be seen in the image. I don't know VBA, what should I do to make this code work?
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, filename:=path & "filename1 & " " & filename2 & " " & filename3 & " " & filename4 & " " & filename5 & " " & filename6 & ".pdf"
Application.DisplayAlerts = True
ActiveWorkbook.Saved = False
Application.Quit
End Sub

Related

Exporting Json data in asp.net vb from MS SQL

I am trying to export data from MS SQL out in a json format in my asp.net web forms application. Problem is it exports with two double quotes around the values instead of just one double quote.
I want it to export like this:
{"bizunitid":"11111","prodlineid":"1","reasonforsurvey":"1"}
but it is coming out like this:
"{""bizunitid"":""11111"",""prodlineid"":""1"",""reasonforsurvey"":""2""}"
I have tried replacing the two double quotes but it always returns two double quotes.
Dim json As String = cmd.ExecuteScalar
streamWriter.Write(json.Replace("""""", Chr(34)))
Not sure if this is what you're looking for, but it's how I've done it when posting JSon to an API for a messaging app with VB.Net:
MessageTitle = MessageTitle.Replace("""", """""")
MessageBody = MessageBody.Replace("""", """""")
Dim strPostData As String = "{" &
"""notification"": {" &
"""sound"": ""default""," &
"""title"": """ & MessageTitle & """," &
"""body"": """ & MessageBody & """" &
"}, " &
"""data"": {" &
"""title"": """ & MessageTitle & """," &
"""body"": """ & MessageBody & """" &
"}," &
"""to"": """ & strRegIDs & """," &
"""priority"": 10 " &
"}"
hopefully that helps a bit

Classic ASP Error Downloading Access Database From Server to Client

I have the following script in a classic asp page:
<%
Response.Write "<script language=""vbscript"">" & vbcrlf
'----------------------------------
Response.Write "sub window_onload" & vbcrlf
'Response.Write "On Error Resume Next" & vbcrlf
Response.Write " dim t1 " & vbcrlf
Response.Write " set xfile = AXFFileDownload.XFRequest " & vbcrlf
Response.Write " AXFFileDownload.AddFile ""c:\contalfinger\tester.mdb"", ""http://" & Request.servervariables("LOCAL_ADDR") & application("portinternet") & "/transfert_fichiers/FZ" & kteur & ".mdb" & chr(34) & vbcrlf
Response.Write " If Err.number <> 0 Then " & vbcrlf
Response.Write " msgbox(""You may not have SA-XFile installed."") " & vbcrlf
Response.Write " End IF " & vbcrlf
'Response.Write " call contalMSN.faireDirectory(""c:\contalfinger"") " & vbcrlf
Response.Write " t1=contalMSN.wait(2) " & vbcrlf
Response.write " AXFFileDownload.Start" & vbcrlf
'Response.Write " call contalMSN.faireCMD(""c:\tmp\fichier2.eml"") " & vbcrlf
'Response.Write " window.close() " & vbcrlf
Response.Write " window.location.href=""loginfinger.asp" & chr(34) & vbcrlf
Response.Write "end sub" & vbcrlf
Response.Write "</script>" & vbcrlf
%>
The problem is that the mdb file on the server has 336KB but when it is downloaded to the client computer it's reduce to 2KB and can't be open due to following error message: Unrecorignised database format.
This script was working before we change server.
Any help will be reallly appreciated.
Thank you
Ok I found it. I had to modify the file found in the below path:
C:\Windows\System32\inetsrv\config\applicationhost.config
<add fileExtension=".mdb" allowed="false" /> for <add fileExtension=".mdb" allowed="true" />

ASP.Net Environment.NewLine stops working half way through a script?

I'm using a script to construct an email, and half way through the NewLines just quit working. I don't see any errors, nor do I can any when it's executed.
Here is the code:
message = message & "Zoning Selections -" & Environment.NewLine & Environment.NewLine
message = message & "Standard Report: " & Request.QueryString("chkList0") & Environment.NewLine
message = message & "Summary Zoning Report: " & Request.QueryString("chkList1") & Environment.NewLine
message = message & "Executive Summary: " & Request.QueryString("chkList2") & Environment.NewLine
message = message & "ZIP Report: " & Request.QueryString("chkList3") & Environment.NewLine
message = message & "Custom Report - Individual Products: " & Request.QueryString("chkList4") & Environment.NewLine
message = message & "Certificate of Occupancy: " & Request.QueryString("chkList5") & Environment.NewLine
message = message & "Building Code Violation: " & Request.QueryString("chkList6") & Environment.NewLine
message = message & "Code Compliance Violation: " & Request.QueryString("chkList7") & Environment.NewLine
message = message & "Fire Code Violation: " & Request.QueryString("chkList8") & Environment.NewLine
message = message & "Saftey Code Violation: " & Request.QueryString("chkList9") & Environment.NewLine
message = message & "Condemnation Report: " & Request.QueryString("chkList10") & Environment.NewLine
message = message & "Property Use: " & Request.QueryString("property_use") & Environment.NewLine
and here is the output:
Zoning Selections -
Standard Report: yes
Summary Zoning Report: yes
Executive Summary: yes
ZIP Report: yes
Custom Report - Individual Products: yes Certificate of Occupancy: yes Building Code Violation: yes Code Compliance Violation: yes Fire Code Violation: yes Saftey Code Violation: yes Condemnation Report: yes Property Use: Office
As you can see, the NewLine works until half way through, and then it simply prints everything on the same line. (also, the other NewLines were added to the file at another time than the ones printing correctly)
What am I missing?
EDIT
Apparently the plain-text formating of an email break all Environment.NewLine line breaks for the rest of the email when it encounters a line longer than 40-50 character (I was using Outlook 2013).
My solution was simple, switch to HTML format and use tags for line breaks instead.

Getting Syntax error when executing ASP ADO Insert

I am concatenating different values and I get the following sql statement:
INSERT INTO Ads (Position, Type, AdType, Link, Width, Height, Path, Korder ) VALUES ('left','1','left1','',1024,768,'FILE1',1)
I really do not see here any errors, however, it says me
Microsoft JET Database Engine error '80040e14'
Syntax error in INSERT INTO statement.
/adm/uploadAdPic.asp, line 68
sql="INSERT INTO Ads (Position, Type, AdType, Link, Width, Height, Path, Korder )"
sql=sql & " VALUES "
sql=sql & "('" & position & "',"
sql=sql & "'" & adType & "',"
sql=sql & "'" & position & adType & "',"
sql=sql & "'" & link & "',"
sql=sql & "" & width & ","
sql=sql & "" & height & ","
sql=sql & "'" & path & "',"
//sql=sql & "" & korder & ","
sql=sql & "" & korder & ")"
//sql=sql & "0)"
Response.Write(sql)
//on error resume next
conn.Execute sql,recaffected //THIS IS LINE 68
Can you, please, help me to find syntax error.
EDIT:
I have found sollution by myself, but it also contains in the answer below.
Position is reserved word.
I tried to modify my insert statement removing different fields and I found out that Position field makes an error.
So I renamed Position to VertPos and it works.
Position is a reserved word in Jet SQL, try change to [Position].
As a general recommendation, add [] to all columns name.
sql="INSERT INTO Ads ([Position], [Type], [AdType], [Link], [Width], [Height], [Path], [Korder] )"
sql=sql & " VALUES "
sql=sql & "('" & position & "',"
sql=sql & "'" & adType & "',"
sql=sql & "'" & position & adType & "',"
sql=sql & "'" & link & "',"
sql=sql & "" & width & ","
sql=sql & "" & height & ","
sql=sql & "'" & path & "',"
//sql=sql & "" & korder & ","
sql=sql & "" & korder & ")"
//sql=sql & "0)"
Response.Write(sql)
//on error resume next
conn.Execute sql,recaffected //THIS IS LINE 68
1) The error is because some of your column names happen to be MSSQL keywords:
' SUGGESTED CHANGE:
INSERT INTO Ads (
[Position], [Type], [AdType], [Link], [Width], [Height], [Path], [Korder])
VALUES ('left','1','left1','',1024,768,'FILE1',1)
2) You're probably much better off using a command object instead of a "naked insert":
Here's an example that shows how to use "objCom.parameters.append()":
http://www.freevbcode.com/ShowCode.asp?ID=3687

how to add Linebreak to a string in asp.net vb

I tried everything, but nothing seems to work!
How the do I put a breakline?!
Dim textMsg as String
textMsg = Body.text & Environment.Newline & _ q1.text & Environment.Newline & _ q2.text & Environment.Newline & _ q3.text & Environment.Newline & _ q4.text '
please help
(with corrent code I get an error cuz of the & Environment.Newline & _ ")
Since you tagged this asp.net, I'll guess that this newline should appear in a web page. In that case, you need to remember that you are creating html rather than plain text, and html ignores all whitespace... including newlines. If you view the source for your page, you'll likely see that the new lines do make it to your html output, but they are ignored, and that's what is supposed to happen. If you want to show a new line in html, use a <br> element:
textMsg = Body.text & "<br>" & _ q1.text & "<br>" & _ q2.text & "<br>" & _ q3.text & "<br>" & _ q4.text
The code above will place the text on several lines. It's interesting that if you view the source now, you'll see that everything is all on the same line, even though it uses several lines for display.
You should add a br:
textMsg = Body.text & "<BR/>" & _ q1.text & "<BR/>" & _ q2.text & "<BR/>" & _ q3.text & "<BR/>" & _ q4.text
Or you can try:
Str & VBNewLine OR Str & VBCrLf
Or set the email message to html. The the will work.
thats the right one:
& (vbCrLf) &
Try this:
dim textMsg as String
textMsg = Body.text & vbNewLine
I preffer .Net Style:
& Environment.NewLine &
It's Is exactly the same that
& (vbCrLf) &

Resources