Link to home
Start Free TrialLog in
Avatar of yasanthax
yasanthaxFlag for United Kingdom of Great Britain and Northern Ireland

asked on

vbdirectory Run-time error '13':

I have copied this code from an existing database to a new test base on my PC and changed the location where each database record will create a folder when the on current record does not have a folder assigned. The field "directory" will have a hyperlink which will open a database folder.  The test database is different from the exiting database and also have a SQL backend just for background.

However I get an error related for VBDirectory.  Am I missing some statements for the test database such as Public Sub OpenLinkedDB() that are failing the VB directory line from being performed?  The database  I am not sure what VBDirectory does.

folder = "C:\Users\USERA\Documents\_sqlTEST\SQLTestDB_Folders\" & Format(Me.P_ID, "\C\A\S\E0000")

If Len(DIR(folder, vbDirectory)) = 0 Then
   MkDir (folder)
   MsgBox "new folder created here: " & folder, vbInformation, "NEW FOLDER"
End If

Thanks
SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yasanthax

ASKER

Hi

Still have issues

Thanks for the very useful code change .  I am still getting errors when calculating the below code.  The paramaters /variables seem to be OK.  Is this some sort of data base corruuption as the DIR command is what fails.

DIR(folder, vbDirectory)
post the string created by this

folder = environ("userProfile") & "\Documents\_sqlTEST\SQLTestDB_Folders\" & Format(Me.P_ID, "\C\A\S\E0000")
debug.print folder


also be aware that the format part of your "folder" path creates more directories.
does the folders "\C\A\S\" already exists?

in creating folders i normally use this codes

place this code in the top of a regular module

Option Compare Database
Option Explicit
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long

Open in new window


'you can then use the function like this

folder = environ("userProfile") & "\Documents\_sqlTEST\SQLTestDB_Folders\" & Format(Me.P_ID, "\C\A\S\E0000")
if right(folder,1)="\" then
   'do nothing
   else
    folder=folder & "\"   ' ADD the trailing slash
end if

MakeSureDirectoryPathExists folder


.
Hi

Still have issues with the new database only.  I ran the following code in the immediate window of both databases, and failed only in my new database. I think it is related to the database missing setups/declarations or corruption

?DIR("C:\Users\USER\Documents\_sqlTEST\SQLTestDB_Folders\CASE0003",vbDirectory)
CASE0003
do a Compact and Repair if you haven't done it yet.

if that is still unsuccessful, create a New blank db and import the objects from the erring db.
btw, are the two PC have the same OS, Office version?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The issue  with code was not because the code was wrong but a unrelated table field name is the database did not follow best practice   naming conventions.