tags:

views:

35

answers:

2

I have some VBA code that looks like this and the aim is to query a csv file and bring back some records. However, I want to be able to query the same file (which sits on a network drive) at the same time from two computers. I tried using the readOnly mode but it still doesn't work. Please help?

   Dim cnt_string  As String
   cnt_string = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & "V:\Data\;" & _
        "Extended Properties = Text;"

    strSQL = "SELECT * FROM " & strData & ".csv " & strData & " WHERE (" & strData & ".APPLICATION_ASSIGNED_TO='" & strBrokerNumber & "')"
    Sheets("Broker").Activate

   Dim rs As ADODB.Recordset

   Set rs = New ADODB.Recordset
   Call rs.Open(strSQL, cnt_string, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText)
   Dim sh As Worksheet
   Set sh = Sheets("Broker")

   Call sh.Range("A10").CopyFromRecordset(rs)
   rs.Close
   Set rs = Nothing
+1  A: 

It may be easier to just make a local temporary copy of the csv and import from that.

If that's not practical due to the size of the .csv, you could check to see if the file is locked by another user and sit in a loop until it becomes available.

mwolfe02
A: 

It can't be done with a CSV.

xiaodai