error message 2465

  • Thread starter Thread starter stan
  • Start date Start date
S

stan

This code is attached to a button to retrieve documents stored in one
location-then moved to another. I'm a little puzzled by a message I get when
I hit the "cancel" button on the form (the rest of it seems t work OK). I
get:

"Microsoft Office Access can't find the field "|" referred to in your
expression (2465)"

This is the code:

Private Sub Command16_Click()
On Error GoTo err_cmdFetchAndStore_Click
Dim strStartSearch As String
Dim strOutgoingDirectory As String
Dim strFilter As String

strOutgoingDirectory = DLookup("FilePath", "Common", "[ID]=1")

strStartSearch = "C:\program files"
strFilter = ahtAddFilterItem(strFilter, "PDF Files (*.PDF)", "* .PDF")


Dim strInputFileName As String
Dim strSQL As String
Dim strFileName As String

DoCmd.RunCommand acCmdSaveRecord


strInputFileName = ahtCommonFileOpenSave( _
OpenFile:=True, _
DialogTitle:="Please select an input file...", _
InitialDir:=strStartSearch, _
Flags:=ahtOFN_HIDEREADONLY)
strFileName = Me.[exp].Value & "-" & "[exp].pdf"
FileCopy strInputFileName, strOutgoingDirectory & "\" & strFileName
strSQL = "Update Requisition Set [exp] = '" & strOutgoingDirectory &
"\" & strFileName & "' where Requisition = " & Me.[exp]
DoCmd.SetWarnings False

DoCmd.RunSQL strSQL

exit_cmdFetchAndStore_Click:
DoCmd.SetWarnings True

Exit Sub
err_cmdFetchAndStore_Click:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume exit_cmdFetchAndStore_Click
End Sub
 
If you cancel the file dialog, it returns a zero-length string.

Modify you code to test for that, e.g.:
If strFilter <> "" Then
'put the rest of the code in here
Else
MsgBox "okay: nothing doing"
End If
 
Thanks so much Allen, but I still can't shake that message. Where in the
code would you put the modification?
--
stan


Allen Browne said:
If you cancel the file dialog, it returns a zero-length string.

Modify you code to test for that, e.g.:
If strFilter <> "" Then
'put the rest of the code in here
Else
MsgBox "okay: nothing doing"
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


stan said:
This code is attached to a button to retrieve documents stored in one
location-then moved to another. I'm a little puzzled by a message I get
when
I hit the "cancel" button on the form (the rest of it seems t work OK). I
get:

"Microsoft Office Access can't find the field "|" referred to in your
expression (2465)"

This is the code:

Private Sub Command16_Click()
On Error GoTo err_cmdFetchAndStore_Click
Dim strStartSearch As String
Dim strOutgoingDirectory As String
Dim strFilter As String

strOutgoingDirectory = DLookup("FilePath", "Common", "[ID]=1")

strStartSearch = "C:\program files"
strFilter = ahtAddFilterItem(strFilter, "PDF Files (*.PDF)", "*
.PDF")


Dim strInputFileName As String
Dim strSQL As String
Dim strFileName As String

DoCmd.RunCommand acCmdSaveRecord


strInputFileName = ahtCommonFileOpenSave( _
OpenFile:=True, _
DialogTitle:="Please select an input file...", _
InitialDir:=strStartSearch, _
Flags:=ahtOFN_HIDEREADONLY)
strFileName = Me.[exp].Value & "-" & "[exp].pdf"
FileCopy strInputFileName, strOutgoingDirectory & "\" & strFileName
strSQL = "Update Requisition Set [exp] = '" & strOutgoingDirectory &
"\" & strFileName & "' where Requisition = " & Me.[exp]
DoCmd.SetWarnings False

DoCmd.RunSQL strSQL

exit_cmdFetchAndStore_Click:
DoCmd.SetWarnings True

Exit Sub
err_cmdFetchAndStore_Click:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume exit_cmdFetchAndStore_Click
End Sub

.
 
You need to check right after you make the call ahtFileOpenSave.

If Len(strInputFileName) = 0 THEN Exit Sub

OR


If Len(strInputFileName) = 0 Then GOTO exit_cmdFetchAndStore_Click

OR


If Len(strInputFileName) <> 0 THEN
'Your code

End IF
exit_cmdFetchAndStore_Click:




John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
works perfectly-Thanks!
--
stan


John Spencer said:
You need to check right after you make the call ahtFileOpenSave.

If Len(strInputFileName) = 0 THEN Exit Sub

OR


If Len(strInputFileName) = 0 Then GOTO exit_cmdFetchAndStore_Click

OR


If Len(strInputFileName) <> 0 THEN
'Your code

End IF
exit_cmdFetchAndStore_Click:




John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

.
 
Back
Top