Results 1 to 5 of 5
  1. #1
    yrstruly is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2024
    Posts
    126

    Button to browse and upload.

    I added a button to browse and store the photo name and location to a table
    When i click button it opens the VBA Code. I tried running it and get "Macro Export Query Name" pop up. The button does not select. tblPlantInspection hs the following columns:
    Code:
    CREATE TABLE tblPlantInspection (    [InspectionID] AUTOINCREMENT PRIMARY KEY,
        [PlantID] TEXT(50) NOT NULL,
        [InspectionDate] DATETIME,
        [DiseaseStatus] TEXT(50),
        [PestPresence] YESNO,
        [NutrientDeficiency] YESNO,
        [Comments] MEMO,
        [PhotoPath] TEXT(255),
        [ReportPath] TEXT(255)
    );



    Pls assist with a VBS Code that will give me this function

    Code:
    Private Sub btnOpenPhoto_Click()    On Error GoTo Err_OpenPhoto
    
    
        If Not IsNull(Me.txtPhotoPath) And Me.txtPhotoPath <> "" Then
            Application.FollowHyperlink Me.txtPhotoPath
        Else
            MsgBox "No photo available to open.", vbExclamation, "Error"
        End If
    
    
        Exit Sub
    
    
    Err_OpenPhoto:
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Open Photo Error"
        Resume Next
    End Sub
    https://drive.google.com/file/d/1I5F...usp=drive_link

    This code opens selection, but i cant see any media files:
    Code:
    Private Sub btnBrowsePhoto_Click()    Dim fd As Object
        Dim strFile As String
    
    
        ' Open File Dialog
        Set fd = Application.FileDialog(3) ' 3 = File Picker
    
    
        With fd
            .Title = "Select a Photo File"
            .Filters.Clear
            .Filters.Add "All Image Files", "*.jpg; *.jpeg; *.png; *.bmp; *.gif; *.tif; *.tiff"
            .AllowMultiSelect = False
    
    
            ' If the user selects a file, store its path
            If .Show = -1 Then
                strFile = .SelectedItems(1)
                Me.Controls("PhotoPath").Value = strFile ' Fix applied here
            End If
        End With
    
    
        ' Cleanup
        Set fd = Nothing
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    You have not given it a starting path?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    yrstruly is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2024
    Posts
    126
    Give an example pls?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    436
    you should use your Control Name (not the Fieldname of the table) on this code:
    Code:
           ' If the user selects a file, store its path
            If .Show = -1 Then
                strFile = .SelectedItems(1)
                Me.Controls("PhotoPath").Value = strFile ' Fix applied here
            End If

    should be:
    Code:
           ' If the user selects a file, store its path
            If .Show = -1 Then
                Me.txtPhotoPath = .SelectedItems(1) ' Fix applied here
            End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 22
    Last Post: 07-16-2015, 11:23 AM
  2. Replies: 3
    Last Post: 12-18-2013, 02:23 PM
  3. Button to Browse for File!
    By floyd in forum Forms
    Replies: 5
    Last Post: 08-23-2013, 09:09 AM
  4. Creating a Browse button to create a Hyperlink
    By detaylor1242 in forum Forms
    Replies: 5
    Last Post: 07-30-2013, 11:48 AM
  5. Link Pictures & Adding Browse Button
    By OldGreg134 in forum Access
    Replies: 1
    Last Post: 06-29-2012, 01:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums