Solved

How is App.path used??

Posted on 2003-11-10
11
1,079 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

803 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