Button not working (1 Viewer)

businesshippieRH

Registered User.
Local time
Today, 15:49
Joined
Aug 8, 2014
Messages
60
I have a button that isn't running any code on click and I can't figure out why. Other buttons on the form work great, and code runs on load. Does anybody have any suggestions? Thanks in advance! Code is:
Code:
Private Sub btn_Upload_Click()
'Check UploadType
Dim RecDist As String
RecDist = DLookup("RecordDistinction", "tbl_Records", "RecordName= '" & Forms!frm_UPLOAD!txt_RecordName & "'")
Dim UploadType As String
UploadType = DLookup("UploadType", "tbl_RecordDistinctions", "RecordDistinction = '" & RecDist & "'")
Debug.Print UploadType
    'Check for entries
    If UploadType = "1" Then
        If Me.txt_PDFLoc = "" Then
            MsgBox "You must upload a PDF file for this Record!", vbExclamation, "Incomplete Form!"
            Me.txt_PDFLoc.SetFocus
            Cancel = True
            Exit Sub
        Else
            'Copy File
            'Set up strings for file names
                'Old Path
                Dim PDFFilePath As String
                    PDFFilePath = Me.txt_PDFLoc
                'New Path
                    'String for adding file extension
                    strFileExtension = GetFileExt(Me.txt_PDFLoc)
                'New Path Strings
                Dim PDFNewTitle As String
                    PDFNewTitle = Me.txt_RecordName & "." & strFileExtension
                Dim PDFRecFile As String
                    PDFRecFile = "T:\DATABASE\RecordsDB\Records\"
                'Combined
                Dim PDFNewFullPath As String
                PDFNewFullPath = PDFRecFile & PDFFilePath
            'Setup FSO Declarations
            Dim FSO As New Scripting.FileSystemObject
            If Not FSO Is Nothing Then 'Error Handling...
            'CopyFile
            FSO.CopyFile PDFFilePath, PDFNewFullPath, False
        End If
        If Me.txt_WORDLoc = "" Then
            MsgBox "You must upload a MS Word file for this Record!", vbExclamation, "Incomplete Form!"
            Me.txt_PDFLoc.SetFocus
            Cancel = True
            Exit Sub
        Else
            'Copy File
            'Set up strings for file names
                'Old Path
                Dim DOCFilePath As String
                    DOCFilePath = Me.txt_WORDLoc
                'New Path
                    'String for adding file extension
                    strFileExtension = GetFileExt(Me.txt_WORDLoc)
                'New Path Strings
                Dim DOCNewTitle As String
                    DOCNewTitle = Me.txt_RecordName & "." & strFileExtension
                Dim DOCRecFile As String
                    DOCRecFile = "T:\DATABASE\RecordsDB\Records\"
                'Combined
                Dim DOCNewFullPath As String
                DOCNewFullPath = PDFRecFile & PDFFilePath
            'Setup FSO Declarations
            Dim FSO As New Scripting.FileSystemObject
            If Not FSO Is Nothing Then 'Error Handling...
            'CopyFile
            FSO.CopyFile DOCFilePath, DOCNewFullPath, False
        End If
    ElseIf UploadType = "1" Then
        If Me.txt_PDFLoc = "" Then
            MsgBox "You must upload a PDF file for this Record!", vbExclamation, "Incomplete Form!"
            Me.txt_PDFLoc.SetFocus
            Cancel = True
            Exit Sub
        Else
            'Copy File
            'Set up strings for file names
                'Old Path
                Dim PDFFilePath As String
                    PDFFilePath = Me.txt_PDFLoc
                'New Path
                    'String for adding file extension
                    strFileExtension = GetFileExt(Me.txt_PDFLoc)
                'New Path Strings
                Dim PDFNewTitle As String
                    PDFNewTitle = Me.txt_RecordName & "." & strFileExtension
                Dim PDFRecFile As String
                    PDFRecFile = "T:\DATABASE\RecordsDB\Records\"
                'Combined
                Dim PDFNewFullPath As String
                PDFNewFullPath = PDFRecFile & PDFFilePath
            'Setup FSO Declarations
            Dim FSO As New Scripting.FileSystemObject
            If Not FSO Is Nothing Then 'Error Handling...
            'CopyFile
            FSO.CopyFile PDFFilePath, PDFNewFullPath, False
        End If
    End If
End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:49
Joined
Feb 19, 2013
Messages
16,553
Well first,

is your button still called btn_Upload
and do you see [Event Procedure] against the on click property?

next, have you set a breakpoint at the beginning of your code and then used F8 to step through the code

And what do you see in the immediate window?
 

businesshippieRH

Registered User.
Local time
Today, 15:49
Joined
Aug 8, 2014
Messages
60
I have checked both of the above. 1/2 the time, my strings print, the other 1/2 they don't. Same is true of running a messagebox (even with nothing else in the code).
 

here4real

Registered User.
Local time
Today, 16:49
Joined
May 1, 2013
Messages
87
Put breakpoints on both DLOOKUPs and hover over your variables to check what values it thinks it is getting, i.e. txt_RecordName and RecDist.
 

businesshippieRH

Registered User.
Local time
Today, 15:49
Joined
Aug 8, 2014
Messages
60
It was pulling some odd stuff thanks to the double declarations. I've given them all individual names and now everything is hunky-dory.
 

Users who are viewing this thread

Top Bottom