Using App.Path Method 
Author Message
 Using App.Path Method

When working with Visual Basic 6.0 and connecting to an
Access Database, I have in the past used App.Path in my
Connection string and it has worked Terrific.

Now I am using Word 2000 and Dian Chapman's tutorials on
Connecting a Word Template to an Access Database.  I've
tried to use the same App.Path in my connection String but
I get a "Variable not defined" error returned.
Is it not possible to use "App.Path" in Word 2000 VBA?

Here is my code:

Private Sub cmdFind_Click()

'declare variables for new connection, new recordset, and
declare variables

Dim vConn As New ADODB.Connection
Dim vRS As New ADODB.Recordset

Dim vFName, vLName, vCustID, vCust1, vAddress, _
    vCity, vState, vZip As String

'provide connection string for data using Jet Provider for
Access Database

vConn.ConnectionString = _
    "data source" = App.Path & "\TestDB.mlb;" & _
    "Provider=Microsoft.Jet.OLEDB.4.0;"

vConn.Open

'test connection state...this can later be commented
out...but it helps
'let you know if the connection was successful when
testing the code

vConnState = vConn.State
If vConnState = 1 Then
    MsgBox "The connection to this database is working!",
vbInformation
Else
    MsgBox "You were unable to connect to the assigned
database!", vbInformation
End If

'open a Recordset with SQL query results...to see if
first/last name matches a record

vRS.Open "Select FirstName, LastName, Address, City,
State, ZipCode from TestDB Where TestDB!Cust_ID = " & _
Chr(34) & vCustID & Chr(34), vConn, adOpenKeyset,
adLockOptimistic

End Sub

I someone could take a look at my code and help me where
I 'm going wrong, I'd greatly appreciate it.

Thank you in advance.

Debi



Sun, 02 Oct 2005 03:04:44 GMT  
 Using App.Path Method
Hi, Debi,

In VBA (which is not entirely like VB), it's Application.Path rather than
App.Path. On this PC, for example, Application.Path returns the string
"C:\Program Files\Microsoft Office\Office". Is that what you want?

--
Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://www.mvps.org/word

Quote:

> When working with Visual Basic 6.0 and connecting to an
> Access Database, I have in the past used App.Path in my
> Connection string and it has worked Terrific.

> Now I am using Word 2000 and Dian Chapman's tutorials on
> Connecting a Word Template to an Access Database.  I've
> tried to use the same App.Path in my connection String but
> I get a "Variable not defined" error returned.
> Is it not possible to use "App.Path" in Word 2000 VBA?

> Here is my code:

> Private Sub cmdFind_Click()

> 'declare variables for new connection, new recordset, and
> declare variables

> Dim vConn As New ADODB.Connection
> Dim vRS As New ADODB.Recordset

> Dim vFName, vLName, vCustID, vCust1, vAddress, _
>     vCity, vState, vZip As String

> 'provide connection string for data using Jet Provider for
> Access Database

> vConn.ConnectionString = _
>     "data source" = App.Path & "\TestDB.mlb;" & _
>     "Provider=Microsoft.Jet.OLEDB.4.0;"

> vConn.Open

> 'test connection state...this can later be commented
> out...but it helps
> 'let you know if the connection was successful when
> testing the code

> vConnState = vConn.State
> If vConnState = 1 Then
>     MsgBox "The connection to this database is working!",
> vbInformation
> Else
>     MsgBox "You were unable to connect to the assigned
> database!", vbInformation
> End If

> 'open a Recordset with SQL query results...to see if
> first/last name matches a record

> vRS.Open "Select FirstName, LastName, Address, City,
> State, ZipCode from TestDB Where TestDB!Cust_ID = " & _
> Chr(34) & vCustID & Chr(34), vConn, adOpenKeyset,
> adLockOptimistic

> End Sub

> I someone could take a look at my code and help me where
> I 'm going wrong, I'd greatly appreciate it.

> Thank you in advance.

> Debi



Sun, 02 Oct 2005 05:04:16 GMT  
 Using App.Path Method
Hi Debi,

App.path is not going to work as you think it might - unless the mdb file is
going to be located in the same directory as the Word application.
(application.path). You will need to identify the path to the mdb either
through hard coding it in or putting it in the registry or a text fiile that
you then read in when the application runs.

HTH and have a great day.

Steve


Quote:
> When working with Visual Basic 6.0 and connecting to an
> Access Database, I have in the past used App.Path in my
> Connection string and it has worked Terrific.

> Now I am using Word 2000 and Dian Chapman's tutorials on
> Connecting a Word Template to an Access Database.  I've
> tried to use the same App.Path in my connection String but
> I get a "Variable not defined" error returned.
> Is it not possible to use "App.Path" in Word 2000 VBA?

> Here is my code:

> Private Sub cmdFind_Click()

> 'declare variables for new connection, new recordset, and
> declare variables

> Dim vConn As New ADODB.Connection
> Dim vRS As New ADODB.Recordset

> Dim vFName, vLName, vCustID, vCust1, vAddress, _
>     vCity, vState, vZip As String

> 'provide connection string for data using Jet Provider for
> Access Database

> vConn.ConnectionString = _
>     "data source" = App.Path & "\TestDB.mlb;" & _
>     "Provider=Microsoft.Jet.OLEDB.4.0;"

> vConn.Open

> 'test connection state...this can later be commented
> out...but it helps
> 'let you know if the connection was successful when
> testing the code

> vConnState = vConn.State
> If vConnState = 1 Then
>     MsgBox "The connection to this database is working!",
> vbInformation
> Else
>     MsgBox "You were unable to connect to the assigned
> database!", vbInformation
> End If

> 'open a Recordset with SQL query results...to see if
> first/last name matches a record

> vRS.Open "Select FirstName, LastName, Address, City,
> State, ZipCode from TestDB Where TestDB!Cust_ID = " & _
> Chr(34) & vCustID & Chr(34), vConn, adOpenKeyset,
> adLockOptimistic

> End Sub

> I someone could take a look at my code and help me where
> I 'm going wrong, I'd greatly appreciate it.

> Thank you in advance.

> Debi



Sun, 02 Oct 2005 07:57:41 GMT  
 Using App.Path Method
Thanks for the help guys.  I was hoping it worked the same
in VBA as VB.  I will do it the hard way and hard code it
in.
Quote:
>-----Original Message-----
>When working with Visual Basic 6.0 and connecting to an
>Access Database, I have in the past used App.Path in my
>Connection string and it has worked Terrific.

>Now I am using Word 2000 and Dian Chapman's tutorials on
>Connecting a Word Template to an Access Database.  I've
>tried to use the same App.Path in my connection String
but
>I get a "Variable not defined" error returned.
>Is it not possible to use "App.Path" in Word 2000 VBA?

>Here is my code:

>Private Sub cmdFind_Click()

>'declare variables for new connection, new recordset, and
>declare variables

>Dim vConn As New ADODB.Connection
>Dim vRS As New ADODB.Recordset

>Dim vFName, vLName, vCustID, vCust1, vAddress, _
>    vCity, vState, vZip As String

>'provide connection string for data using Jet Provider
for
>Access Database

>vConn.ConnectionString = _
>    "data source" = App.Path & "\TestDB.mlb;" & _
>    "Provider=Microsoft.Jet.OLEDB.4.0;"

>vConn.Open

>'test connection state...this can later be commented
>out...but it helps
>'let you know if the connection was successful when
>testing the code

>vConnState = vConn.State
>If vConnState = 1 Then
>    MsgBox "The connection to this database is working!",
>vbInformation
>Else
>    MsgBox "You were unable to connect to the assigned
>database!", vbInformation
>End If

>'open a Recordset with SQL query results...to see if
>first/last name matches a record

>vRS.Open "Select FirstName, LastName, Address, City,
>State, ZipCode from TestDB Where TestDB!Cust_ID = " & _
>Chr(34) & vCustID & Chr(34), vConn, adOpenKeyset,
>adLockOptimistic

>End Sub

>I someone could take a look at my code and help me where
>I 'm going wrong, I'd greatly appreciate it.

>Thank you in advance.

>Debi
>.



Mon, 03 Oct 2005 00:39:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. using application path (app.path)

2. Using an explicit path with OpenRecordset method?

3. Best method of determining path, relative path and/or flie name

4. Using app.path

5. Using app.path in ADO data control connectionstring

6. Using app.path as part of connectionstring

7. Windows Directoy using APP.PATH?

8. using the APP.PATH command ...

9. Shell using App.Path

10. Using App.Path

11. Where is App.Path when using PPC Emulator?

12. Paths and App.Path

 

 
Powered by phpBB® Forum Software