Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Anpu Massri   on Jan 31 In MS Office Category.

  
Question Answered By: Estella Mitchell   on Jan 31

A few points, some of which might help ...

1) Please tidy up your code. In particular, indent it properly, so it's
readable.

2) Your connection  string is quite different to one I've used to open an
Access database from Excel. I don't know what the significance of this is,
but FYI I'm including mine.

Private mConnection As New ADODB.Connection
Call mConnection.Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &
Path & "\Production substitute.mdb")

I pass the connection string as a parameter on the Open call, but I doubt
that this is significant.

3) I'm unhappy about your second sSQL string. Two things. Firstly, there
is no space between [Create-date] and FROM. This might be confusing Access.
Secondly, you aren't generating quotes in the SQL around StrSearchtxt
although it presumably contains a string.

You absolutely need to put a display/msgbox of sSQL before trying to use
it, so that you can check what the SQL statement  really looks like.

I suggest you stick with your first SQL statement for the moment - it's much
simpler and eliminates one area of uncertainty.

4) You have three rsData.Open statements:

'rsData.Open sSQL, sConnect
'rsData.Open sSQL, sConnect, 3, 1
rsData.Open

The last of these is the one that's not commented out - but it gives no
information on what database to open or what SQL to execute. That's never
going to work.

The other two are similar. They pass the SQL to the Open, and the
connection STRING. I doubt that this is right. You need to pass the
connection itself.

An open from my code:

Dim RS As ADODB.Recordset: set  RS = New ADODB.Recordset
Call RS.Open(Source:=SQL, ActiveConnection:=mConnection,
CursorType:=adOpenKeyset)

The first line could presumably also be a direct New call:

Dim RS As New ADODB.Recordset
Call RS.Open(Source:=SQL, ActiveConnection:=mConnection,
CursorType:=adOpenKeyset)

My suspicion is that (4) is the most important of these points. You need to
make sure that the RS Open has the information needed to attach it to the
connection.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 


Tagged: