Data Control

All my forms have link with the database by data control. the path look like this "C:\WINDOWS\DESKTOP\scan\SOC.mdb"  how about if someone moves the databse from this location, the program will not run! is ther any solution! thanks
Who is Participating?
MikeP090797Connect With a Mentor Commented:
Check on startup if the file exist, using Dir. If it doesn't, either create an empty database, or ask the use to enter the database path using Open File Dialog
You could write a routine to check for the existance of your
database file.  If it has been moved, then you could have a
routine look for it, then change the databasename property
to the new path.  I built an activeX control to do this.

hadorth11Author Commented:
Hi Mike, Thanks for answering my question but can you show me how to do it. thanks
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

In addition to the proposed solution, you could store the Database Name in an INI/Registry setting.

In the Form_Initialize Event you would read the Setting and verify the existence of the DB.

If the file/path are good, set the datacontrol.databasename = INI setting
To check if a file exist:

If Dir("C:\Windows\Db1.mdb")="" then 'Not exist
 CreateDatabase "C:\Windows\Db1.mdb", dbLangGeneral
End If

hadorth11Author Commented:
Guys, you are wonderful.. I will give your web address to all my friends!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.