Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Help Global Function
Brent Rinehart 
        
3 years ago
I got a private sub working great for what I need, but I need to repeat about 8 times and yes I can just repeat this which I usually do as I have always skipped making global functions because I can never get them to work most of the time, well tonight I gave it a good two hours on the following with it working up until it gets to the strSQL = "Update JobT SET... and it keeps telling me too few parameters needs 1? Any help what I am doing wrong I would appreciate, I know its got to be something really simple I am not catching.
Brent Rinehart OP  @Reply  
        
3 years ago
Public Function OpenPathLocation(PathLocation As String)
    On Error GoTo ErrHandler

    Dim PathName As String
    PathName = ""

    ' Check if Folder Path already exists for the current record
    PathName = Nz(DLookup([PathLocation], "JobT", "JobID = " & Forms!JobF.JobID.Value), "")

    If PathName <> "" Then
        ' Open the folder location
        Application.FollowHyperlink PathName
    Else
        ' Prompt the user to enter the folder path
        PathName = InputBox("Enter the folder path:")
        
        ' Check if the user cancels or enters a zero-length string
        If PathName = "" Then
            MsgBox "No folder path entered. Exiting without saving."
            Exit Function
        End If
        
        ' Store the folder path in the table for the current record
        Dim strSQL As String
        strSQL = "UPDATE JobT SET [PathLocation] = '" & PathName & "' WHERE JobID = " & CInt(Forms!JobF.JobID.Value)

        MsgBox strSQL
        
        Debug.Print "SQL Statement: " & strSQL ' Add this line for debugging
        
        CurrentDb.Execute strSQL
        
        MsgBox "Folder path stored successfully!"
    End If

ExitFunction:
    Exit Function

ErrHandler:
    MsgBox "Error: " & Err.Description
    Resume ExitFunction
End Function
Brent Rinehart OP  @Reply  
        
3 years ago
In the JobT is a field called HorzPath which should be feed to the PathLocation through a onclick event on a form
Adam Schwanz  @Reply  
           
3 years ago
You have brackets around PathLocation, it's probably looking for a field instead of the variable you're passing it.
Adam Schwanz  @Reply  
           
3 years ago
If that's not it, add a Msgbox PathLocation right before you set strSQL to see what it is

I would also use ! instead of . here Forms!JobF!JobID.Value but it may work fine how you have it
Kevin Robertson  @Reply  
          
3 years ago
I would send PathLocation as a Variant, not a String. It will throw an error if what is sent to the Function is Null.
I got this to work with no errors.

Public Function OpenPathLocation(PathLocation As Variant)

    Dim PathName As String
    Dim strSQL As String
    
    On Error GoTo ErrHandler

    PathName = Nz(DLookup("PathLocation", "JobT", "JobID = " & Forms!JobF!JobID), "")

    If PathName <> "" Then
        Application.FollowHyperlink PathName
    Else
        PathName = InputBox("Enter the folder path:")

        If PathName = "" Then
            MsgBox "No folder path entered. Exiting without saving."
            Exit Function
        End If

        strSQL = "UPDATE JobT SET PathLocation=""" & PathName & """ WHERE JobID=" & Forms!JobF!JobID
        CurrentDb.Execute strSQL
        Forms!JobF.Recordset.Requery
        MsgBox "Folder path stored successfully!"
    End If

ExitFunction:
    Exit Function

ErrHandler:
    MsgBox "Error: " & Err.Description
    Resume ExitFunction
End Function
Brent Rinehart OP  @Reply  
        
3 years ago
I will give this a shot after work and report back thank you guys
Brent Rinehart OP  @Reply  
        
3 years ago

Brent Rinehart OP  @Reply  
        
3 years ago
Sorry Guys still no Luck on the onclick event of my button I have tried OpenPathlocation (HorzPath), OpenPathlocation ([HorzPath]), OpenPathlocation ("HorzPath") and no luck. the code bellow is what I have in the form it self and it works great I just duplicate it on every button for now. I do alter the path name for what ever path if is for.    

Private Sub TagFolderBtn_Click()

    Dim TagPath As Variant
    
    ' Check if DispatchPath already exists for the current record
    TagPath = DLookup("TagPath", "JobT", "JobID = " & Me.JobID.Value)
    
    If Not IsNull(TagPath) Then
        ' Open the folder location
        Application.FollowHyperlink TagPath
        
        Exit Sub
    End If
    
    ' Prompt the user to enter the folder path
    TagPath = InputBox("Enter the folder path:")
    
    ' Check if the user cancels or enters a zero-length string
    If TagPath = "" Or IsNull(TagPath) Then
        MsgBox "No folder path entered. Exiting without saving."
        Exit Sub
    End If
    
    ' Store the folder path in the table for the current record
    CurrentDb.Execute "UPDATE JobT SET TagPath = '" & TagPath & "' WHERE JobID = " & Me.JobID.Value
    
    MsgBox "Folder path stored successfully!"

End Sub


This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developers.
 

Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 9/6/2026 5:27:02 AM. PLT: 1s