Solved

How is App.path used??

Posted on 2003-11-10
11
1,086 Views
Last Modified: 2009-07-29
Ok guys here it goes.... I made a program using VB6.0, but when installing it on a friend's PC.. it didn't work he got a path error.
I was told to use App.path & "\databasename.mdb" .... but i really don't get it.
The person wasn't to specific 'bout how to use app.path.

Note: I use the data control on forms to access the database, the database is name is "directorio.mdb" and it's located in "C:\Mis documentos\Directorio\".
So i would aprecciate an example code on how to use app.path.

Thanx.

- MetalfreaK -
0
Comment
Question by:metalfreak
11 Comments
 
LVL 3

Expert Comment

by:cindy_k
ID: 9720118
Here's the deal with App.Path.  It returns the Directory where the application is located. If your database is in the Same Directory as your application then App.Path will be a big help.
If the database can be anywhere on the machine, then you will need a way for your users to choose a directory path if the application can't find the database.

Ex 1:
C:\Cynthia_File\Database.mdb
C:\Cynthia_File\Application.exe
Here App.Path should be C:\Cynthia_File\  which could be used to find the database too, since they are in the same directory.

Ex 2:
C:\My documents\Database.mdb
C:\Cynthia_File\Application.exe
Here App.Path would be useless since the Database is in My Documents and the path returned would be C:\Cynthia_File.

I hope this helps,
Cynthia
0
 

Author Comment

by:metalfreak
ID: 9720144
Good answer.. but i kinda knew that already Cynthia.
I wanted to get on explanation on how to use it in my program. How to use it in code.
For example u say: "Here App.path should be C:\Cynthia_File\" , but how do i do that?
How do i make app.path take that value.
Explain it a little, and please some code.
0
 
LVL 7

Expert Comment

by:_agj_
ID: 9720203
you aint getting the pt metalfreak....

if your database is going to be in the same folder as the exe file u run, then use:

strDatabasepath = app.path & "\" & databasename.mdb

or something like that....
now, strDatabasePath can be used as the database filename inclusive of the path.

But, if u are placing ur database in some path which is not at all related to the exe file's location, then you could
include mebbe an common dialog control to let the user select the database location.

However, if the database path happens to be related, as in, lets say ur exe is in a folder called c:\myprog\exe
and ur database will always be in c:\myprog\db, then u cud do a :

strDatabasepath = app.path & "\..\db" & databasename.mdb

PS. App.Path is NOT to be set to any value. It holds the path where the exe is currently running from. Thats all.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:metalfreak
ID: 9720284
Ok, i get what App.path does..I think

So I use this: strdatabasepath = App.Path & "\directorio.mdb"

Both the exe and the database r in the same folder:
"C:\Mis documentos\Directorio\directorio.exe"
"C:\Mis documentos\Directorio\directorio.mdb"

but what do I do with strdatabasepath, i mean should I declare strdatabasepath? and how do i use it?
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9720429
App.Path returns a string, so you don't really have to declare it but it is advisable:       Dim strdatabasepath as string

You can use it everywhere:      

If you want to open this file then use:

Dim BlaBla As String
BlaBla = App.Path & "\databasename.mdb"

Open BlaBla for input as #1
...
Close #1
...

If you have a DirListBox then use:    >>  Dir1 = App.Path   <<    This will change it's path to App.Path
Chdir App.Path will change the current folder to this folder.




0
 

Author Comment

by:metalfreak
ID: 9722998
Ok but i use data controls on my form to connect with the database if i use app.path.. should i remove the data controls??. Here's the code from 1 command of "frmadd" (were you add any new data to the database). This is the actual code from my program. So please modify it to see how should app.path de used.

Data1.UpdateRecord
Data1.Recordset.Bookmark = Data1.Recordset.LastModified
Text1.Enabled = False
Text2.Enabled = False
submenuedit.Enabled = True
submenudelete.Enabled = True
submenusave.Enabled = False
submenucancel.Enabled = False
Data1.Enabled = True
Text7.Text = "Estado actual: Registro almacenado correctamente".

0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 100 total points
ID: 9728634
Just use:

'Put this before all your other data1 method
Data1.DatabaseName = App.Path & "directorio.mdb"

~ fantasy ~
0
 

Author Comment

by:metalfreak
ID: 9729074
Doesn't work... i get an data type conversion error when saving the record.

Data1 Properties:
* connect: Access
* databasename: (it gets it from Data1.DatabaseName = App.Path & "\directorio.mdb" in code)
* defaulttype: 2-Use Jet
* recordsetype: 1-Dynaset
* exclusive: false

Here's the code.. pls modify it

Add New:
Data1.Recordset.AddNew
Text1.Enabled = True
Text2.Enabled = True

Save:
Data1.UpdateRecord
Data1.Recordset.Bookmark = Data1.Recordset.LastModified
Data1.Enabled = True
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9729209
The problem is related to your bounded data control. Try this

Add New:
Private Sub cmdAdd_Click()
  On Error GoTo AddErr
  data1.Recordset.AddNew

  Exit Sub
AddErr:
  MsgBox Err.Description
End Sub

Save:
Private Sub cmdUpdate_Click()
  On Error GoTo UpdateErr

  data1.Recordset.UpdateBatch adAffectAll
  Exit Sub
UpdateErr:
  MsgBox Err.Description
End Sub
0
 
LVL 1

Expert Comment

by:Lycaon
ID: 9897395
Note:  App.Path does NOT return a trailing \ UNLESS your program is running from the root of a drive.   So, if your app is running from c:\, App.Path will return "C:\", BUT if you're running your app from C:\Blah\ then App.Path will return "C:\Blah".  Note the lack of a trailing \.  Keep that in mind when coding.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question