26. oktober 2000 - 08:56
Der er
1 kommentar og
1 løsning
ODBB/Query
Jeg bruger idag Query til at trække data ud fra Navision via deres odbc driver. Jeg har lavet en række ark, som med mellemrum skal opdateres med nye afgrænsninger (eks. dato)Idag skal jeg vælge funktionen \"ændre afgrænsning\" - ændre afgrænsningen i Query og derefter opdater.
Kan man indtaste afgrænsningen i Excel, hvorefter ændringen sker uden at man skal via Query ?
26. oktober 2000 - 09:07
#1
Navision giver selv følgende eksempel, som jeg kan sende til dig hvis du skriver på ploughgaard@bigfoot.com:
\' This macro retrieves data from Navision Financials
Sub HentNaviData()
Msg = \"Update data from Navision Financials?\"
Style = vbOKCancel + vbQuestion
Title = \"C/ODBC\"
response = MsgBox(Msg, Style, Title)
If response = vbOK Then
Application.Calculation = xlManual
SQLConnectionID = SQLOpen(\"DSN=Sample C/ODBC 32 bit;Option=Integer;Decimal=Decimal\", Range(\"ErrorSheet!$D$1\"), 2)
Range(\"ErrorSheet!$D1\").ClearContents
Range(\"ErrorSheet!$A$1..$C$10\") = SQLError()
If Not IsError(Range(\"ErrorSheet!$A$1\")) Then
Msg = \"It was not possible to etablish connection. \" _
+ \"The C/ODBC driver returned the following error message: \" + Range(\"ErrorSheet!$C$1\")
Style = vbOKOnly + vbCritical
response = MsgBox(Msg, Style, Title)
SQLClose connectionNum:=SQLConnectionID
Application.Calculation = xlAutomatic
Exit Sub
End If
SQLExecQuery _
connectionNum:=SQLConnectionID, _
queryText:=\"SELECT \"\"No_\"\", \"\"Name\"\", \"\"Net Change\"\" FROM \"\"G/L Account\"\" WHERE (\"\"Account Type\"\" = 0)\" + _
\"AND (\"\"Date Filter\"\" = \'..\" + Range(\"Ratios!$B$1\") + \"\')\" + _
\"AND (\"\"Department Filter\"\" = \'\" + Range(\"Ratios!$B$2\") + \"\')\" + _
\"AND (\"\"Project Filter\"\" = \'\" + Range(\"Ratios!$B$3\") + \"\')\" + _
\"ORDER BY \"\"No_\"\" \"
Range(\"ErrorSheet!$A$11..$C$20\") = SQLError()
If Not IsError(Range(\"ErrorSheet!$A$11\")) Then
Msg = \"The C/ODBC driver returned the following error message: \" + Range(\"ErrorSheet!$C$13\")
Style = vbOKOnly + vbCritical
response = MsgBox(Msg, Style, Title)
SQLClose connectionNum:=SQLConnectionID
Application.Calculation = xlAutomatic
Exit Sub
End If
SQLRetrieve _
connectionNum:=SQLConnectionID, _
destinationRef:=Range(\"Chart_of_Accounts!$A$1\"), _
ColNamesLogical:=True
Range(\"ErrorSheet!$A$21..$C$30\") = SQLError()
SQLClose connectionNum:=SQLConnectionID
Application.Calculation = xlAutomatic
Msg = \"Data has been updated\"
Style = vbInformation
response = MsgBox(Msg, Style, Title)
Else
Msg = \"Data was not updated\"
Style = vbOKOnly + vbInformation
response = MsgBox(Msg, Style, Title)
End If
Sheets(\"Ratios\").Activate
End Sub