Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intermittent Error assigning value to text box 1

Status
Not open for further replies.

GabeC

Programmer
Apr 17, 2001
245
0
0
US
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
 
check that there's actually a file selected from the dialog, i.e. check fd.SelectedItems(1) has a value

--------------------
Procrastinate Now!
 
Thank you for these pieces of information. I will implement these changes and see if this resolves the issue.

Thanks,

Gabe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top