I want to write some VBA that retrieves data from a lotus notes database into excel. I will then have some other code that manipulates the data for the user. I have managed to do this with MS Query manually. However when I start to put into VBA my problems start.
As I do not know Sql I use the macro record function. This worksso far so good. The problems seem to start when I re-run the macro and try to save the workbook. Excel just sits there with the CPU running at 99%. I left the pc for an hour and it was still in the same condition with the status bar showing save.
Any ideas as it is very frustrating.
I have pasted the macro recorded below:
VB:
Sub Macro4()
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=premax;Database=Premax\se000273.nsf;Server=local;UserName=John Cross/bsp;EncryptMaxSubquery=20;MaxStmtLen=4096;MaxRels=20;M" _
), Array( _
"axVarcharLen=1024;KeepTempIdx=1;MaxLongVarcharLen=1024;ShowImplicitFlds=0;MapSpecialChars=1;ThreadTimeout=60;" _
)), Destination:=Range("E1"))
.CommandText = Array( _
"SELECT ""7___Special___c___Import_Export___e___Fault___Event___Action_1"".DocIDNo, ""7___Special___c___Import_Export___e___Fault___Event___Action_1"".Action, ""7___Special___c___Import_Export___e___Fault___Event___Action_1"".Action_AddI" _
, _
"nfo_ViewDspl, ""7___Special___c___Import_Export___e___Fault___Event___Action_1"".Cause, ""7___Special___c___Import_Export___e___Fault___Event___Action_1"".CreatingDate, ""7___Special___c___Import_Export___e___Fault___Event___Action_1""." _
, _
"CustDocRef, ""7___Special___c___Import_Export___e___Fault___Event___Action_1"".Customer FROM ""7___Special___c___Import_Export___e___Fault___Event___Action"" ""7___Special___c___Import_Export___e___Fault___Event___Action_1"" WHERE (""7" _
, _
"___Special___c___Import_Export___e___Fault___Event___Action_1"".CreatingDate Between '2007-02-04 14:47:01' And '2007-03-05 07:14:37') ORDER BY ""7___Special___c___Import_Export___e___Fault___Event___Action_1"".DocIDNo" _
)
.Name = "Query from premax_range"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceConnectionFile = _
"C:\Documents and Settings\cjohn\Desktop\Faults development\Query from premax_range.dqy"
.refresh BackgroundQuery:=False
End With
End Sub
Bookmarks