Connection String

S

Samuel

I have the code below that requires the connection string, my question is
what connection string do I have to supply within the access file itself

Dim obRecSet As Recordset
Dim obConn As New Connection
Dim sSQL As String

sSQL = "SELECT * FROM [Order Details] WHERE OrderID = " & OrderID

'Get all Order detail records
obConn.Open
Set obRecSet = obConn.Execute(sSQL)

obConn.Close

'Loop for each record
While obRecSet.EOF = False



'Update the submit flag
UpdateSubmit (obRecSet.Properties("OrdeDetailID"))
'Update the cash book

'Insert log record

obRecSet.MoveNext

'End loop
Wend
 
N

Norman Yuan

Samuel said:
I have the code below that requires the connection string, my question is
what connection string do I have to supply within the access file itself

Dim obRecSet As Recordset
Dim obConn As New Connection


You declared a Connection object here, which will be created when it is
referred the first time in later code, as new Connection.

If you want to connect to Access file you are currently in, you may not need
a new Connection object. You can use CurrentProject.Connection object, which
is already open. Usually, you only need to open a new connection from inside
your Access app when you try to access data from other source than the
Access file your are in.

Dim sSQL As String

sSQL = "SELECT * FROM [Order Details] WHERE OrderID = " & OrderID

'Get all Order detail records
obConn.Open


You need to give an ConnectioNString argument to the Open() method let the
Connection object know which/what database/data source it is to connect.
Alternatively, you can set Connection.ConnectionString property before
calling Open() method. What the ConnectionString looks like depends on what
data source you are to connect.
 
A

Albert D. Kallal

You can use the built in one.....

eg:

Dim obRecSet As dao.Recordset
dim strSql as string


strSql = "SELECT * FROM [Order Details] WHERE OrderID = " & OrderID
set obRecSet = currentdb.OpenrecordSet(strSql)

While obRecSet.EOF = False

etc....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top