Please Help on folder

extreme

Registered User.
Local time
Today, 04:41
Joined
Sep 27, 2004
Messages
51
Thanks To Kiwiman he helped me with this code

This puts a new folder in the directory I need with the clients company name
on the next form I put details of the site but I need to place another folder into the company folder of the name of the site Can someone please help as I am a noobie to this I have several books but does'nt explain

Private Sub Command8_Click()
Dim lngRetval As Long
Dim strName As String, strFile As String, strFileName As String


strName = Me.ClientName ' then name of the text box that holds your site
strFile = "c:\AsbestosSurveyPro\data\" ' default file location
strFileName = strFile & strName ' the full directory name

If Dir(strFileName, vbDirectory) <> "" Then
' Directory exists, insert your file output code here
Else
' Directory doesn't exist
' Prompt user if he wants it to be created
lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")
If lngRetval = 6 Then
' User asked to create dir, so create it.
' Well, the nested directory doesn't exist, but need
' to check if the vbtemp exists to avoid similar error
If Dir(strFile, vbDirectory) <> "" Then
' Just create the sub-directory
MkDir (strFileName)
Else
' Create main and then sub-dir
MkDir (strFile)
MkDir (strFileName)
End If
' Check if it got created
If Dir(strFileName, vbDirectory) <> "" Then
' Let user know it was success
MsgBox ("Path created succesfully.")
Else
' Let user know it was failure
MsgBox ("Error creating path.")
End If
Else
' User asked not to create dir
MsgBox ("Path was not created.")
End If
End If

Dim strDocName As String

strDocName = "Survey"
DoCmd.OpenForm strDocName, , , , acFormAdd

End Sub
 
Howsit

This is just in an extension of the previous one. Basically when creating directories, the process will fail if the sub directories are missing. So you just keep app;ying the same sort of logic. There may be a better way of doing this, but this is what I have come up with. You may consider putting the code in a Public Module in order to reduce any maintenance.

This is not code that I created, I found it on the web somewhere, but I know not where...

Again this code is dependent on the "other" folder being a text box on your form...

Good luck

Code:
Private Sub Command8_Click()
Dim lngRetval As Long
Dim strName As String, strFile As String, strFileName As String, strFileNameFull As String, strOther As String


strName = Me.ClientName ' then name of the text box that holds your site
strOther = Me.YourControl ' the other name of your text box contianing other folder
strFile = "c:\AsbestosSurveyPro\data\" ' default file location
strFileName = strFile & strName ' the directory contianing the company name
strFileNameFull = strFileName & "\" & strOther ' the full name

If Dir(strFileNameFull, vbDirectory) <> "" Then
    ' Directory exists, insert your file output code here
Else
    ' Directory doesn't exist
    ' Prompt user if he wants it to be created
    lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")

    If lngRetval = 6 Then
        ' User asked to create dir, so create it.
        ' Well, the nested directory doesn't exist, but need
        ' to check if the vbtemp exists to avoid similar error
        If Dir(strFileName, vbDirectory) <> "" Then
            ' Just create the sub-directory
            MkDir (strFileNameFull)
        Else
            If Dir(strFile, vbDirectory) <> "" Then
                ' Just create the Long and Medium directories
                MkDir (strFileName)  ' Create the medium path
                MkDir (strFileNameFull) ' Create the long path
            Else
                'Make all the directories
                MkDir (strFile) ' Create the short directory
                MkDir (strFileName)  ' Create the medium path
                MkDir (strFileNameFull) ' Create the long path
                        
            End If
        End If


    ' Check if it got created
    If Dir(strFileNameFull, vbDirectory) <> "" Then
        ' Let user know it was success
        MsgBox ("Path created succesfully.")
    Else
        ' Let user know it was failure
        MsgBox ("Error creating path.")
    End If
    Else
        ' User asked not to create dir
        MsgBox ("Path was not created.")
    End If
End If

Dim strDocName As String

strDocName = "Survey"
DoCmd.OpenForm strDocName, , , , acFormAdd

End Sub
 
Howsit

This is just in an extension of the previous one. Basically when creating directories, the process will fail if the sub directories are missing. So you just keep app;ying the same sort of logic. There may be a better way of doing this, but this is what I have come up with. You may consider putting the code in a Public Module in order to reduce any maintenance.

This is not code that I created, I found it on the web somewhere, but I know not where...

Again this code is dependent on the "other" folder being a text box on your form...

Good luck

Code:
Private Sub Command8_Click()
Dim lngRetval As Long
Dim strName As String, strFile As String, strFileName As String, strFileNameFull As String, strOther As String


strName = Me.ClientName ' then name of the text box that holds your site
strOther = Me.YourControl ' the other name of your text box contianing other folder
strFile = "c:\AsbestosSurveyPro\data\" ' default file location
strFileName = strFile & strName ' the directory contianing the company name
strFileNameFull = strFileName & "\" & strOther ' the full name

If Dir(strFileNameFull, vbDirectory) <> "" Then
    ' Directory exists, insert your file output code here
Else
    ' Directory doesn't exist
    ' Prompt user if he wants it to be created
    lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")

    If lngRetval = 6 Then
        ' User asked to create dir, so create it.
        ' Well, the nested directory doesn't exist, but need
        ' to check if the vbtemp exists to avoid similar error
        If Dir(strFileName, vbDirectory) <> "" Then
            ' Just create the sub-directory
            MkDir (strFileNameFull)
        Else
            If Dir(strFile, vbDirectory) <> "" Then
                ' Just create the Long and Medium directories
                MkDir (strFileName)  ' Create the medium path
                MkDir (strFileNameFull) ' Create the long path
            Else
                'Make all the directories
                MkDir (strFile) ' Create the short directory
                MkDir (strFileName)  ' Create the medium path
                MkDir (strFileNameFull) ' Create the long path
                        
            End If
        End If


    ' Check if it got created
    If Dir(strFileNameFull, vbDirectory) <> "" Then
        ' Let user know it was success
        MsgBox ("Path created succesfully.")
    Else
        ' Let user know it was failure
        MsgBox ("Error creating path.")
    End If
    Else
        ' User asked not to create dir
        MsgBox ("Path was not created.")
    End If
End If

Dim strDocName As String

strDocName = "Survey"
DoCmd.OpenForm strDocName, , , , acFormAdd

End Sub

Thanks again KiWiMan I have pasted into form but it comes up with a compile error

I think its because the code is for the same form
I have one form called clients where I put new client details in with a button to click new site when I click this button it creates a new folder in the clients name that works perfect.

On the next form called new site, I put details of the site address Im working on, I need another new folder put in the clients folder with the name of the site.

I cant put in the directory

strFile = "c:\AsbestosSurveyPro\data\" ' default file location

I need the site address to find the clients folder automaticly

Any Idea

Sorry for being a pain and thanks for everyones help

Thank You

Have you any Ideas

Thanks For Your Time (I May Have To Pay Someone To Finish This DB Off Because Its Taken To Long)
 
Last edited:
Hi Extreme

Sorry, been having major internet problems today...

Just a couple of queries. I take you have at least the following tables (my names may not necessarily match yours) in your db:
1. tblclient info (PK - ClientID)
2. tblsites (PK - Site id - linked to tblClients on ClientID)
3. tblSamples (PK - SampleID - linked to tbleSites on SiteID)

If so, your main Client form, can then have a subform attached (frmSites) to it, which itself has a subform attached to it (frmSamples).

You can then have multiple sites per client, and multiple samples per site etc etc

Please see attached db - I have something similar. Not properly tested or compiled or anything, just basic coding (begged and borrowed from everywhere). Adapted to the above I think. This will let you store the sample doc location in the db, and open from the db.
 

Attachments

The directory creation will work as long as the default location is already set up..
 
The directory creation will work as long as the default location is already set up..

Thanks for helping me

I have Clients and Sites I have'nt got samples

In my relationships I have Client, Sites, Survey and thay are all linked together

I see in your db that you have a Query I have'nt.

Sorry for being a pain, but Im not all that good with access A freind of mine started this last year and he had a motorcycle accident at christmas and past away so I am trying to finish it off.
 
Hi Extreme

My db was not supposed to replace yours, as yours may have more functionality in it - it was just to illustrate how it could be done. Also your table design could be capturing a lot more information regarding sites, clients etc. Don't be concerned with my table names \ forms as I took a guess. I have called mine samples - you have called yours survey - the point being that this table is linked to the sites table.

You can delete the query, in my db - it does nought.
 
Hi Extreme

My db was not supposed to replace yours, as yours may have more functionality in it - it was just to illustrate how it could be done. Also your table design could be capturing a lot more information regarding sites, clients etc. Don't be concerned with my table names \ forms as I took a guess. I have called mine samples - you have called yours survey - the point being that this table is linked to the sites table.

You can delete the query, in my db - it does nought.

Thanks kiwiman I have been trying all day but I will try and sort it out
Thanks for you time
 
Howzit

If you still have no luck, load your db up and I'll havea look at it.

Cheers
 

Users who are viewing this thread

Back
Top Bottom