I have the following code. When you click the button, it opens a dialog box for the user to select a file. Once the file is selected, the file name is assigned to a text box. Most of the time this works but ocassionally the following error is produced: "can't assign a value to this object".
This is the setup:
app.mdb - sits on a network drive that multiple users (up to 5 concurrently) use. Links in tables from data.mdb
data.mdb - sits on a network drive.
Here is the code that gets executed when the cmdOpen button gets clicked. I have highlighted the line of code where the error is thrown.
Private Sub cmdOpen_Click()
On Error GoTo Err_cmdOpen_Click
' open file dialog or open the doc
Dim sDocName As String
Dim fd As FileDialog
Dim vFilePath As Variant
Dim sFileInfo as String
If IsNull([Form]![FileName]) Then 'vs FilePath
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
If .Show = -1 Then 'ok
'get filename and path
'update current documents record w/filename
sFileInfo = fd.SelectedItems(1)
[Form]![FilePath] = sFileInfo 'This is the line of code where the error happens
'get filename
[Form]![FileName] = FileNameOnly(sFileInfo)
End If
Set fd = Nothing
End With
Else 'open the doc
Dim x As Long
Dim FormName As Long 'hWnd
Dim FName As String
FName = [Form]![FilePath]
FormName = Me.hWnd
x = ShellExecute(FormName, "Open", FName, 0&, 0&, vbNormalFocus)
End If
Exit_cmdOpen_Click:
Exit Sub
Err_cmdOpen_Click:
MsgBox Err.Description
Resume Exit_cmdOpen_Click
End Sub
Any ideas what is going on?
Thanks,
Gabe
This is the setup:
app.mdb - sits on a network drive that multiple users (up to 5 concurrently) use. Links in tables from data.mdb
data.mdb - sits on a network drive.
Here is the code that gets executed when the cmdOpen button gets clicked. I have highlighted the line of code where the error is thrown.
Private Sub cmdOpen_Click()
On Error GoTo Err_cmdOpen_Click
' open file dialog or open the doc
Dim sDocName As String
Dim fd As FileDialog
Dim vFilePath As Variant
Dim sFileInfo as String
If IsNull([Form]![FileName]) Then 'vs FilePath
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
If .Show = -1 Then 'ok
'get filename and path
'update current documents record w/filename
sFileInfo = fd.SelectedItems(1)
[Form]![FilePath] = sFileInfo 'This is the line of code where the error happens
'get filename
[Form]![FileName] = FileNameOnly(sFileInfo)
End If
Set fd = Nothing
End With
Else 'open the doc
Dim x As Long
Dim FormName As Long 'hWnd
Dim FName As String
FName = [Form]![FilePath]
FormName = Me.hWnd
x = ShellExecute(FormName, "Open", FName, 0&, 0&, vbNormalFocus)
End If
Exit_cmdOpen_Click:
Exit Sub
Err_cmdOpen_Click:
MsgBox Err.Description
Resume Exit_cmdOpen_Click
End Sub
Any ideas what is going on?
Thanks,
Gabe