This question already has answers here:
How to enter newline character in Oracle?
(3 answers)
Closed 4 years ago.
I have written VBA code in excel to create a SP in oracle and it working fine.
But when I opened SP in oracle it showing entire code in single line. I have tried known ways to give line breaks but nothing works.
My actual VB code:
If sp_exist_chk_flag > 0 Then
Else
cmd_meta.CommandText = "create or replace PROCEDURE TEST_SP " & Chr(13) & _
"As" & Chr(13) & _
"REP DATA_REP.REP_ID%TYPE;" & Chr(13) & _
"SELECT REP_ID INTO REP FROM DATA_REP WHERE REP_NAME='xyz';" & Chr(13) & _
"COMMIT;" & Chr(13) & _
"END;"
cmd_meta.Execute
MsgBox "SP Created"
End If
In Oracle I can see SP is created as below
create or replace PROCEDURE TEST_SP As REP DATA_REP.REP_ID%TYPE; SELECT REP_ID INTO REP FROM DATA_REP WHERE REP_NAME='xyz'; COMMIT; END;
My actual SP is too long, so my vb code making it very long line.
Please help me on this with VB code or oracle command to look like an actual SP with proper line breaks in oracle.
Not sure if it will make a difference, but try using the vbCrLf constant instead of Chr(13).
If sp_exist_chk_flag > 0 Then
Else
cmd_meta.CommandText = "create or replace PROCEDURE TEST_SP " & vbCrLf & _
"As" & vbCrLf & _
"REP DATA_REP.REP_ID%TYPE;" & vbCrLf & _
"SELECT REP_ID INTO REP FROM DATA_REP WHERE REP_NAME='xyz';" & vbCrLf & _
"COMMIT;" & vbCrLf & _
"END;"
cmd_meta.Execute
MsgBox "SP Created"
End If
Related
I'm using PowerPivot, and I'm creating a table in the datamodel using the next code:
Set ObjConn = ActiveWorkbook.Connections.Add2( _
Name:= "SomeConnName", _
Description:="DescSomeConn", _
ConnectionString:="OLEDB;Provider=OraOLEDB.Oracle;Data Source=XXXX;User ID=YYYY;Password=ZZZ;Persist Security Info=true", _
CommandText:="SELECT * FROM mytable", _
lCmdtype:=xlCmdSql, _
CreateModelConnection:=True, _
ImportRelationships:=False)
It works well, except it always create the table named "Query".
I already searched in Microsoft Documentation and googled this way too much and I can't directly find where or how to set the table/query name.... or how to rename it after it was created.
Help is appreciated.
EDIT
Thanks to #QHarr guide, I changed my approach to this:
ActiveWorkbook.Queries.Add Name:="QueryXY09", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = OleDb.DataSource(""provider=OraOLEDB.Oracle.1;data source=MyDWHConn;"", [Query=""SELECT * FROM mytable""])" _
& Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Source"
ActiveWorkbook.Connections.Add2 _
"Query - QueryXY09", "Connection to the 'QueryXY09' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=QueryXY09;Extended Properties=", _
"""QueryXY09""", 6, True, False
Which makes the goal, now I can set the name of the connection.
But this represents two problems. First data extraction is clearly slower, it seems it is using .net libraries, also, it looks like a double step.
Second, now I don't have a place to store the password, neither connection accept the user id/password for this approach. This last is the most worrisome, since the purpose of this is, of course, the automation of the extraction of data. However, I notice that, when I moved the file to a testing server, it prompted me for the user/password once, then I closed everything, open again and there was no prompt. So, where was the password saved?
I am playing with a script that sends emails from an excel sheet. the body of my email is not compiling. However I have wrapped everything in "" with & _ breaks for when it goes too far and .value _ & vbNewLine & _ for line breaks
I have tried annotating out chunks of the email body to fish out the syntax error
.Body = "Hello " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"this is Paul from the XYZ and I just left you a voicemail message for you. " & _
"We are reaching out to you because you’ve been identified in the XYZ system as someone who manages XYZ " & _
"The XYZ form, which you have been using, will be retired after XYZ and be replaced with a new process and system. " & _
"If you onboard XYZ for your organization, this means you will be directly impacted. " & _
"We need to collect your information to set you up in our new system and ensure there is no interruption moving forwards. " & _
"We will reach out again and if you can please provide the following information below: ".Value _
& vbNewLine & vbNewLine & _
"Best email to contact you: ".Value _
& vbNewLine & _
"Best phone number to reach you: ".Value _
& vbNewLine & _
"Best time of day to schedule our next call: ".Value _
& vbNewLine & vbNewLine & _
"If you have any questions or concerns, please don’t hesitate to reach out directly to me at XYZ ".Value _
& vbNewLine & vbNewLine & _
"Thank you, "
Email should go out. But instead I get a syntax error compile error
"Best email to contact you: ".Value _
There's the error. That .Value member call is illegal, a string literal doesn't have members. You probably mean to be doing this:
"Best email to contact you: " & .Value _
Same here:
"Best phone number to reach you: ".Value _
And here:
"Best time of day to schedule our next call: ".Value _
And here too:
"We will reach out again and if you can please provide the following information below: ".Value _
Now, the inconsistency of whether you put the & at the end or at the start of a line, makes the code extremely hard to parse. Decide whether you want it at the end or at the beginning, and stick to it.
I have a function (bastardised from Ron DeBruin's Website) that saves the active or selected sheet as a pdf and sends it as an attachment in outlook. It still works for everyone I've given it to but lately, it is not working on my PC. I keep getting the error message as if VBA cannot save the file (due to the path being invalid or the name being used already and not wanting to overwrite)
Running on various PCs that are either running on Windows 10 or 7 (I'm on Win10) I've tried changing the save file path & the filename in the code to something more simple and I still have the same issues. I tried the file on another machine running windows 10 and had no issues. I've also tried checking Microsoft Add-Ins and everything is fine.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub RDB_Worksheet_Or_Worksheets_To_PDF_And_Create_Mail()
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more than one sheet selected," & vbNewLine & _
"be aware that every selected sheet will be published"
End If
'Call the function with the correct arguments
'Tip: You can also use Sheets("YourSheetName") instead of ActiveSheet in the code(sheet does not have to be active then)
FileName = RDB_Create_PDF(Source:=ActiveSheet, _
FixedFilePathName:="C:\Users\" & Environ("Username") & "\Documents\Container Shipment Reports\" & (Range("G4").Value) & ".pdf", _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'For a fixed file name use this in the FixedFilePathName argument
'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:="XXXXXX.XXXXXXX#XXXXX.com.au", _
StrCC:="XXXXXX.XXXXXXX#XXXXX.com.au; XXXXXX.XXXXXXX#XXXXX.com.au", _
StrBCC:="", _
StrSubject:="Container Shipment Report " & (Range("G4").Value) & ".", _
Signature:=True, _
Send:=False, _
StrBody:="<body>Hello,</body><br>" & _
"<body>Please see the attached Container Shipment Report# " & (Range("G4").Value) & " from " & (Range("E4").Value) & "." & _
"<br><br>" & "Thank you.</body>"
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exists"
End If
Application.Quit
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
This should convert to PDF, attach to an email, send the email and then close Excel. At the moment I am just getting the MsgBox response from the code, "Not possible to create PDF, possible reasons: etc".
(there is also a function to stop the excel file saving as it is meant to be a blank template.) As I said this seems to be an issue only on my machine but as it works on other computers I'm thinking there's no issue with the code.
I have an issue, have an AutoCAD file with a ton of data links and would like to update only the data links related to a speciffic table.
Simmilar to the functionality of selecting a table with data links, right clicking and selecting Update Table Data Links.
i have the following code:
Private Sub Update_table_data_link(tblRef As AcadTable)
ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "K" & vbCr
End Sub
It works but updates all the data links in the drawing (which is a problem) so a perfect solution would either let me get what links are associated to tblRef
and change the line to:
ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "D" & vbCr & "datalink_name_from_tblRef" & vbCr
or directly send the command to update the links to tblRef
After much digging around and a lot of help, here is the answer:
Private Sub Update_table_data_link(tblRef As AcadTable)
ThisDrawing.SendCommand "DATALINKUPDATE " & vbCr & "U" & vbCr & Ent2lspEnt(tblRef) & vbCr & vbCr
End Sub
Public Function Ent2lspEnt(entObj As AcadEntity) As String
'Designed to work with SendCommand, which can't pass objects.
'This gets an objects handle and converts it to a string
'of lisp commands that returns an entity name when run in SendCommand.
Dim entHandle As String
entHandle = entObj.Handle
Ent2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
End Function
note that "Update_table_data_link" has a table as input
I'm working with legacy code here and I'm not sure how much I could or should change, but I have code that looks for something like "SIC CODE 4000"
However the data html database I pull it from (we use a copy and paste) has updated their code to have:
"SiC CODE
4000"
Currently the code is:
Const strSic = "SIC Code "
However I now need it to add line breaks.
I tried modifying the code to say:
Const strSic = "SIC Code" & Chr(10) & Chr(10) & Chr(10)
But I get a compile error saying "Constant expression required"
I tried using "SIC Code \n\n\n" but maybe I'm not thinking the right character for line break.
Any suggestions?
The code for a new line is vbNewLine:
Const strSic = "SIC Code" & vbNewLine & vbNewLine & vbNewLine
Update:
To be a bit more detailed see the VBA constants:
vbNewLine = Chr(13)+Chr(10) on Windows and Chr(13) on Mac
vbCr = Chr(13)
vbLf = Chr(10)
So if you only need Chr(10) you should use vbLf (like Excel Hero's answer).
Try this:
Const strSic = "SIC Code" & vbLf & vbLf & vbLf
Yes vbNewLine is the correct code : )