Hello,
Is there something obvious why my code below does not work?
I get "Compile Error" Sub or function not defined
Is there something obvious why my code below does not work?
Code:
Private Sub btnBrowse_Click()
' File targets
Dim sourceFile, targetFile, target As String
' Error Location
On Error GoTo Error_btnBrowse_Click
' Check to see if its an add or remove
If btnBrowse.Caption = "Browse" Then
With Application.FileDialog(3)
.Title = "Choose WI File Location"
.InitialFileName = DLookup("fileBaseOutput", "tblConfig")
.AllowMultiSelect = False
' Show the box
If .show = -1 Then
' Get the name
sourceFile = .SelectedItems(1)
target = Right(sourceFile, Len(sourceFile) - InStrRev(sourceFile, "\"))
targetFile = DLookup("fileBaseOutput", "tblConfig") + "\" + target
If Not FileExist(targetFile) Then
MoveFile sourceFile, targetFile
End If
' Set the old data to nothing
txtLocation.Value = target
btnBrowse.Caption = "Remove"
End If
End With
ElseIf btnBrowse.Caption = "Remove" Then
' Set the temporary name for the file
Dim tempFileName As String
tempFileName = txtLocation.Value
' Rename the button
btnBrowse.Caption = "Browse"
' Requery to get the data
txtLocation.Value = ""
sourceFile = DLookup("fileNotices", "tblConfig") + "\" + tempFileName
targetDir = Application.CurrentProject.Path + "\Removed"
targetFile = targetDir + "\" + tempFileName
' Make a removed directory
If Not FolderExists(targetDir) Then
MkDir targetDir
End If
' Delete the file in removed
If FileExists(targetFile) Then
Kill targetFile
End If
' Move the file
MoveFile sourceFile, targetFile
End If
' Requery
DoCmd.RunCommand acCmdSaveRecord
' Get Out
Exit Sub
I get "Compile Error" Sub or function not defined
Last edited: