I have to apologize again.
I forgot to give you this function that you will need to make this work.
Please accept my apologies for a second omission on my part!!
Just copy & paste this function in under your existing code.
Code:
Function FileExists(ByVal strFile As String, Optional bFindFolders As Boolean) As Boolean
'Purpose: Return True if the file exists, even if it is hidden.
'Arguments: strFile: File name to look for. Current directory searched if no path included.
' bFindFolders. If strFile is a folder, FileExists() returns False unless this argument is True.
'Note: Does not look inside subdirectories for the file.
'***Not being used in production.***
Dim lngAttributes As Long
'Include read-only files, hidden files, system files.
lngAttributes = (vbReadOnly Or vbHidden Or vbSystem)
If bFindFolders Then
lngAttributes = (lngAttributes Or vbDirectory) 'Include folders as well.
Else
'Strip any trailing slash, so Dir does not look inside the folder.
Do While Right$(strFile, 1) = "\"
strFile = Left$(strFile, Len(strFile) - 1)
Loop
End If
'If Dir() returns something, the file exists.
On Error Resume Next
FileExists = (Len(Dir(strFile, lngAttributes)) > 0)
End Function
My 'On Current' Event code is as follows:
Code:
Private Sub Form_Current()
Dim strPartNumber As String, strPath As String, strFile As String, strPathFile As String
strPath = "C:\"
Me.PartNumber.SetFocus
strPartNumber = Me.PartNumber.Text 'This assumes your Part Number field is named 'PartNumber'.
strFile = strPartNumber & ".txt" 'Put the correct file extension in where I put ".txt"
strPathFile = strPath & strFile
'MsgBox strPathFile 'I just put this in to see if I was getting the correct path & file name.
If FileExists(strPathFile) Then
Me.HasFile.SetFocus 'This assumes that your check box on the Form is named 'HasFile'
Me.HasFile.Value = True
Else
Me.HasFile.SetFocus
Me.HasFile.Value = False
End If
End Sub
Let me know if this gets you closer!!
Again - sorry I didn't run the code before I gave it to you!!