Benjamin Bolduc
Registered User.
- Local time
- Today, 11:53
- Joined
- Jan 4, 2002
- Messages
- 169
Hello everyone,
I'm working on a customer file management system for our database. The purpose is to provide a quick link to all of the files within a customers specific folder.
Open selecting a customer, a folder is created using the [Account Name], (If it does not already exist.) You can then select a file to open from a combobox or click a button to open the folder to paste files into it.
It is working great so far except for one problem. If the Account Name has invalid characters, such as \/:*?"<>|, it cannot create the folder.
Is there a way to modify the folder name to change the invalid characters? If the folder name is different from the Account Name, how can it query it?
I appreciate your help as I have limited knowledge in VBA. Here is the code I am working with:
Private Sub cbSelectFile_AfterUpdate()
On Error GoTo Err_cbSelectFile_AfterUpdate
Dim cPath As String
cPath = "\\Dataserver2\Database\Monadnock Security Systems Inc. Database\Customer Files\" & Forms![Central Form]![Account Name] & "\"
Me.tbHidden.SetFocus
Application.FollowHyperlink cPath & "\" & cbSelectFile
Exit_cbSelectFile_AfterUpdate:
Exit Sub
Err_cbSelectFile_AfterUpdate:
If Err.Number = 432 Then 'File name or class not found during Automation operation
MsgBox "The '" & cbSelectFile & "' file can not be opened.", vbCritical, "Invalid File Type"
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_cbSelectFile_AfterUpdate
End If
End Sub
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
Dim cPath As String
cPath = "\\Dataserver2\Database\Monadnock Security Systems Inc. Database\Customer Files\" & Forms![Central Form]![Account Name] & "\"
On Error Resume Next
If Dir(cPath, vbDirectory) > vbNullString Then
End If
MkDir cPath
On Error GoTo Err_Form_Open
Me.lcbSelectFile.Caption = "Select a file to open from " & Forms![Central Form]![Account Name] & " folder:"
Dim lngCount As Long
lngCount = Me.cbSelectFile.ListCount
Call Update_cbSelectFile
Exit_Form_Open:
Exit Sub
Err_Form_Open:
If Err.Number = 76 Then 'path not found
MsgBox "You do not have access to the " & cPath & " directory.", vbCritical, "Directory Access Error"
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Form_Open
End If
End Sub
Public Function Update_cbSelectFile()
On Error GoTo Err_Update_cbSelectFile
Dim cPath As String
cPath = "\\Dataserver2\Database\Monadnock Security Systems Inc. Database\Customer Files\" & Forms![Central Form]![Account Name] & "\"
Dim sPath As String
Dim sFileList As String
Dim sFileName As String
sFileList = ""
sFileName = Dir(cPath)
Do While sFileName <> ""
sFileList = sFileList & sFileName & ";"
sFileName = Dir
Loop
Me.cbSelectFile.RowSource = sFileList
Me.cbSelectFile.Requery
Exit_Update_cbSelectFile:
Exit Function
Err_Update_cbSelectFile:
If Err.Number = 2176 Then 'The setting for this property is too long
MsgBox "Combo box can not contain more than 255 records. No records will be displayed.", vbCritical, "Record Source Error"
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Update_cbSelectFile
End If
End Function
I'm working on a customer file management system for our database. The purpose is to provide a quick link to all of the files within a customers specific folder.
Open selecting a customer, a folder is created using the [Account Name], (If it does not already exist.) You can then select a file to open from a combobox or click a button to open the folder to paste files into it.
It is working great so far except for one problem. If the Account Name has invalid characters, such as \/:*?"<>|, it cannot create the folder.
Is there a way to modify the folder name to change the invalid characters? If the folder name is different from the Account Name, how can it query it?
I appreciate your help as I have limited knowledge in VBA. Here is the code I am working with:
Private Sub cbSelectFile_AfterUpdate()
On Error GoTo Err_cbSelectFile_AfterUpdate
Dim cPath As String
cPath = "\\Dataserver2\Database\Monadnock Security Systems Inc. Database\Customer Files\" & Forms![Central Form]![Account Name] & "\"
Me.tbHidden.SetFocus
Application.FollowHyperlink cPath & "\" & cbSelectFile
Exit_cbSelectFile_AfterUpdate:
Exit Sub
Err_cbSelectFile_AfterUpdate:
If Err.Number = 432 Then 'File name or class not found during Automation operation
MsgBox "The '" & cbSelectFile & "' file can not be opened.", vbCritical, "Invalid File Type"
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_cbSelectFile_AfterUpdate
End If
End Sub
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
Dim cPath As String
cPath = "\\Dataserver2\Database\Monadnock Security Systems Inc. Database\Customer Files\" & Forms![Central Form]![Account Name] & "\"
On Error Resume Next
If Dir(cPath, vbDirectory) > vbNullString Then
End If
MkDir cPath
On Error GoTo Err_Form_Open
Me.lcbSelectFile.Caption = "Select a file to open from " & Forms![Central Form]![Account Name] & " folder:"
Dim lngCount As Long
lngCount = Me.cbSelectFile.ListCount
Call Update_cbSelectFile
Exit_Form_Open:
Exit Sub
Err_Form_Open:
If Err.Number = 76 Then 'path not found
MsgBox "You do not have access to the " & cPath & " directory.", vbCritical, "Directory Access Error"
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Form_Open
End If
End Sub
Public Function Update_cbSelectFile()
On Error GoTo Err_Update_cbSelectFile
Dim cPath As String
cPath = "\\Dataserver2\Database\Monadnock Security Systems Inc. Database\Customer Files\" & Forms![Central Form]![Account Name] & "\"
Dim sPath As String
Dim sFileList As String
Dim sFileName As String
sFileList = ""
sFileName = Dir(cPath)
Do While sFileName <> ""
sFileList = sFileList & sFileName & ";"
sFileName = Dir
Loop
Me.cbSelectFile.RowSource = sFileList
Me.cbSelectFile.Requery
Exit_Update_cbSelectFile:
Exit Function
Err_Update_cbSelectFile:
If Err.Number = 2176 Then 'The setting for this property is too long
MsgBox "Combo box can not contain more than 255 records. No records will be displayed.", vbCritical, "Record Source Error"
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Update_cbSelectFile
End If
End Function