Solved

How is App.path used??

Posted on 2003-11-10
11
1,091 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 86
Protecting vb6 & .Net code Obfuscation 18 213
which modules are active in VB6 project? 6 56
Userform to show a range in excel. 3 33
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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