Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-20-2015, 01:31 PM   #1
businesshippieRH
Newly Registered User
 
Join Date: Aug 2014
Posts: 60
Thanks: 17
Thanked 0 Times in 0 Posts
businesshippieRH is on a distinguished road
Button not working

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

businesshippieRH is offline   Reply With Quote
Old 02-20-2015, 04:19 PM   #2
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 10,435
Thanks: 40
Thanked 3,368 Times in 3,263 Posts
CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice
Re: Button not working

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?
__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button
CJ_London is offline   Reply With Quote
Old 02-24-2015, 06:38 AM   #3
businesshippieRH
Newly Registered User
 
Join Date: Aug 2014
Posts: 60
Thanks: 17
Thanked 0 Times in 0 Posts
businesshippieRH is on a distinguished road
Re: Button not working

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).

businesshippieRH is offline   Reply With Quote
Old 02-24-2015, 07:01 AM   #4
here4real
Newly Registered User
 
Join Date: May 2013
Posts: 87
Thanks: 2
Thanked 5 Times in 5 Posts
here4real is on a distinguished road
Re: Button not working

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.
here4real is offline   Reply With Quote
The Following User Says Thank You to here4real For This Useful Post:
businesshippieRH (02-24-2015)
Old 02-24-2015, 12:40 PM   #5
businesshippieRH
Newly Registered User
 
Join Date: Aug 2014
Posts: 60
Thanks: 17
Thanked 0 Times in 0 Posts
businesshippieRH is on a distinguished road
Re: Button not working

It was pulling some odd stuff thanks to the double declarations. I've given them all individual names and now everything is hunky-dory.

businesshippieRH is offline   Reply With Quote
Reply

Tags
button , form control , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Button is not working Sunnylei Forms 13 11-20-2011 07:41 AM
Add Button not working now?? YNWA Forms 2 08-24-2011 01:17 AM
Button not working dtreeves Forms 3 12-22-2009 02:23 PM
Button not working Andre Reports 4 12-07-2008 01:08 PM
Command button not working kabir_hussein Forms 4 12-17-2003 03:32 AM




All times are GMT -8. The time now is 10:30 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World