ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Access database error (https://www.excelbanter.com/excel-programming/404221-access-database-error.html)

Fredrik WG

Access database error
 
I have sporadically found an error when accessing an access database from
Excel VBA, sometimes I get double entries (lines) in Excel when there is only
one entriy in Access database. The double entriy I see are just a copy of an
existing line.

Database are located in house on network drive.

Question: Does anyone know the cause of this error / behaviour? The solution
today is to verify that no double entries exists, and if it does, promt
operator to re-run macro until it pass.

VBA Code:
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=MS Access Database;DBQ=" & FileToOpen & ";FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;" _
)), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT BOAT.ShortID, BOAT.Rev, BOAT.TestGroup, BOAT.MPPoint,
BOAT.MPDescription, BOAT.LtLow, BOAT.LtHigh, BOAT.Meas, BOAT.Unit,
BOAT.Cause, " _
, _
"BOAT.CompName, BOAT.Action, BOAT.Comments, BOAT.TSResp, BOAT.Pos,
BOAT.CompNumb, BOAT.RepairHistory, BOAT.RepCnt, BOAT.Status, BOAT.DateUpdate,
" _
, _
"BOAT.IR, BOAT.DateStamp, BOAT.ID, BOAT.IDNumber, BOAT.MPGroup,
BOAT.CustomerCom, BOAT.Loc FROM BOAT ORDER BY BOAT.IDNumber, BOAT.Loc")

.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False

End With


All times are GMT +1. The time now is 01:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com