I am using Excel 2019 Home and Business
I have built SQL string what works if I use it trough PGAdmin, but if I execute it trough vbs i get relation error.
This is how I create connection
db.Open "DSN=" & databaseSource & "; Database=" & databaseName & "; Uid=" & databaseUsername & "; Pwd=" & databasePassword
cmd.CommandType = adCmdText
cmd.ActiveConnection = db
this is the SQL string I am trying to execute. Same string works if used trough PGAdmin
strSQL = "INSERT INTO public.kaup (grupp2, nimi, yhik, viit, grupp1, algyhik, suurus, kaal, baasyhik, tootjamaa, taimoot, teema, varvikood, brand, liik, nimetus, tellitav, varviryhm, kollektsioon) VALUES (" & setT("brand") & ", " & Chr(39) & setName & Chr(39) & ", " & setT("unit") & ", " & setT("isRecipe") & ", " & setT("mainGroupNr") & ", " & setT("algyhik") & ", " & setT("size") & ", " & totalWeightStr & ", " & setT("baasyhik") & ", " & setT("origin") & ", " & setT("taimoot") & ", " & setT("season") & ", " & setT("factoryColor") & ", " & setT("categoryNr") & ", " & setT("productTypeNr") & ", " & setT("factoryName") & ", " & setT("orderable") & ", " & setT("colorGroup") & ", " & setT("collection") & ")"
cmd.CommandText = strSQL
On Error GoTo errorHandler
cmd.Execute
String looks like this:
INSERT INTO public.kaup (grupp2, nimi, yhik, viit, grupp1, algyhik, suurus, kaal, baasyhik, tootjamaa, taimoot, teema, varvikood, brand, liik, nimetus, tellitav, varviryhm, kollektsioon) VALUES (186, 'Nord Active Plus Set Safari + Granite Chassis', 'TK', 1, 2, 'tk', 'N/A', 9.5, 'PCE', 'PL', 'ZZZ', '2020', 166, 2, 885, 'Nord Active Plus Set', 1, 15, null)
I assume I need to add some tables in SQL string, but how would I do that in vbs?
The Table andmebaas is located in 3 different schemas.
Also I removed one another problematic column because in Database it has this written in Create table.
If i add k_m_vaba in my code ith will say it has no relation to kaup_kaibemaks
CONSTRAINT kaup_kaibemaks FOREIGN KEY (k_m_vaba)
REFERENCES eesti.kaibemaks (kaibemaks) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE RESTRICT
NOT VALID,
How do I add more connections or relations in my SQL string so that when INSERT new row It knows where are these tables located at?
Found solution. before executing query had to set path to one of the other schemas.
Then Database was able to figure out all the other schemas by itself.
SET search_path TO eesti,public; INSERT INTO kaup (...
Unable to SaveCopyAs to proper path using vba:
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "Rounds " & Month(Sheet4.Cells(1, 2)) & " - " & Year(Sheet4.Cells(1, 2))
The code is saving just short of the file path. Folder is located on a folder on the desktop but the new file is being saved to the desktop.
Path returns the folder the workbook is saved under. Sounds like you want:
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "\Rounds " & Month(Sheet4.Cells(1, 2)) & " - " & Year(Sheet4.Cells(1, 2))
If you run this:
Sub TestMe()
Debug.Print ThisWorkbook.Path
End Sub
you would see something like: C:\Users\Username\Desktop in the immediate window.
Thus, if you run your code like this:
Debug.Print ThisWorkbook.Path & "Rounds " & Month(Sheet4.Cells(1, 2))
You would most probably see something like this:
C:\Users\Username\DesktopRounds 12 and this is not what you need. There is obviously a / missing after the Desktop. Thus, put it there and try further:
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "\Rounds " & Month(Sheet4.Cells(1, 2)) & " - " & Year(Sheet4.Cells(1, 2))
This is probably a simple task, but for some reason I’m not quite getting it right.
I want to save a copy of the active workbook to a different file. I have used a code in the past to do this with the date, but I want to remove the date. The code I used in the past is the following:
ActiveWorkbook.SaveCopyAs "P:\Wealth Management Products & Services\Investment Research & Communication\Structured Products\" &Format(dtdate) & " " & "Structured Product Tool" & " " & "Bloomberg" &".xlsm"
What I want is to remove the date, so the name will be: Structured Product Tool Bloomberg
I thought it would be the following:
ActiveWorkbook.SaveCopyAs "P:\Wealth Management Products Services\Investment Research & Communication\Structured Products\"Structured Product Tool" & " " & "Bloomberg" & ".xlsm"
But I’m getting an error.
Does anyone know the correct code for this?
Thanks, Peter
You are missing an ampersand & in your statement:
ActiveWorkbook.SaveCopyAs "P:\Wealth Management Products & Services\Investment" _
& "Research & Communication\Structured Products\" _
& "Structured Product Tool" & " " & "Bloomberg" & ".xlsm"
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 use Excel VBA to create emails in Thunderbird using command line arguments, found here:
http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29
Composing the mails works, but how can I send it automatically?
Alternatively, is there a button in Thunderbird to send all composed emails at once?
VBA code looks like this:
Option Explicit
Sub thunderbird()
Dim strTh As String
Dim strCommand As String
strTh = "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe "
strCommand = strCommand & " -compose " & "to=" & Chr(34) & "foo#bar.de" & Chr(34)
strCommand = strCommand & ",preselectid=id2"
strCommand = strCommand & ",subject=" & Chr(34) & "wow so email" & Chr(34)
strCommand = strCommand & ",body=" & Chr(34) & "anything" & Chr(10) & "more" & Chr(34)
Call Shell(strTh & strCommand, vbNormalFocus)
End Sub
Unfortunately, this is not possible as such. However, https://support.mozilla.org/questions/1144493 lists alternatives, in case they work for you.
From UI, File -> Send Unsent Messages should work (you may need to activate the menu bar) to send all composed messages.