Results 1 to 9 of 9
  1. #1
    stingray is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    22

    Save image file into a table through Form

    I have a subform like this:



    Click image for larger version. 

Name:	2025-01-31 152952.png 
Views:	43 
Size:	30.7 KB 
ID:	52647
    I would like to register a new "product" here. Users come here and enter a new product and a barcode image. I don't want to deal with updating an existing image just yet.
    I found a way to drop an image file into the white box here to get a full file path, but then how do I register it in the table with the rest of the information on the same form?
    the images are very small, so I want to store it in the DB.

    The code here does not work. It does not link to the rest of the info on the form. Please help.

    ADDED:
    Maybe I just get the file path when an image is D&D, and when the user clicks on "Add/Update" the whole entry is inserted into a table. That is more like it. Please help with the code. Thank you!


    Private Sub ProcessFile(ByVal sFile As String)


    Dim dbs As Database
    Dim rst As Object
    Dim rsA As Object
    Dim PictFld As Object
    Dim strFile As String


    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("Product")
    Set PictFld = rst("BarcodeImage")

    'sFile is the full path to the image file

    Set rsA = PictFld.Value
    strFile = Dir(sFile) 'Get File Name ONLY


    rst.Edit


    rsA.AddNew
    rsA("FileData").LoadFromFile sFile
    rsA.Update


    rsA.Close
    rst.Update

    rst.Close
    dbs.Close
    Set fld = Nothing
    Set rsA = Nothing
    Set rst = Nothing
    Set dbs = Nothing


    End Sub

  2. #2
    jojowhite's Avatar
    jojowhite is online now Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    on the click of your "Add/Update" button, you first save the record on the form:

    Code:
    Me.Dirty = False
    If Not IsNull(Me!txtBarcodeDropZone) Then
        If Len(Dir$(Me!txtBarcodeDropZone))<>0 And Not IsNull(Me!CustomerSKU) Then
            Call ProcessFile(Me!CustomerSKU, Me!txtBarcodeDropZone)
        End If
    End If

    the updated code:

    Code:
    Private Sub ProcessFile(ByVal CustomerSKU As String, ByVal sFile As String)
    
    
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset2
        Dim rsA As DAO.Recordset2
        Dim strFile As String
    
    
        strFile = Dir(sFile) 'Get File Name ONLY
        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset("SELECT BarCodeImage FROM Product WHERE CustomerSKU = '" & CustomerSKU & "'")
        If Not (rst.BOF And rst.EOF) Then
            rst.MoveFirst
            Set rsA = rst(0).Value
            rst.Edit
            With rsA
                If Not (.BOF And .EOF) Then
                    ' delete old image
                    .MoveFirst
                    .Delete
                End If
                ' add new image
                .AddNew
                .Fields("FileName") = strFile
                .Fields("FileData").LoadFromFile sFile
                .Update
            End With
            rst.Update
        End If
        rst.Close
        Set rsA = Nothing
        Set rst = Nothing
        Set dbs = Nothing
    End Sub

    pls. take note that adding an attachment field can rapidly bloat your db.
    it is best to only keep the Path of the image to a Short text field on Product table.

  3. #3
    Join Date
    Apr 2017
    Posts
    1,792
    You can read the barcode value into database field using scanner. You can have a text box in form, which constructs a barcode string from barcode value (adding starting and ending strings), and which uses barcode format to display the result as barcode image (so user can read the value from there using a scanner).

    I did something like this some 15 years ago, but I don't have it anymore.

  4. #4
    stingray is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    22
    Quote Originally Posted by ArviLaanemets View Post
    You can read the barcode value into database field using scanner. You can have a text box in form, which constructs a barcode string from barcode value (adding starting and ending strings), and which uses barcode format to display the result as barcode image (so user can read the value from there using a scanner).

    I did something like this some 15 years ago, but I don't have it anymore.
    This is interesting. I might do it.
    The thing, is that I wanted to generate a UPC-A barcode from a 12-digit UPC, but I couldn't do it. I imported a function from here: https://www.idautomation.com/font-en...VBA_Properties
    It seems that it does the calculation, but free UPC-A barcode font that I picked up from somewhere did not show correctly. I think I need to buy their font, so I switched direction.

    Thank you for your comment!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Post 4 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    stingray is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    22
    Hi, jojowhite

    This is great! I can see how this is going to work very dimly (because I am not a programmer) but I am so grateful. I've been looking at this and thinking, because I need to modify this to make it work.
    I have a feeling that user needs to save the basic info first, then add this barcode image, and you cannot do everything at once with just one click to save all.

    Thank you!

  7. #7
    stingray is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    22
    I am getting closer.
    Jojowhite's code is great, and gave me a clue. Now, I am making this a two-step process, because I don't know what else I can make this work.

    Save other data (SKU, UPC, Desc, Case) into the table first THEN drag and drop the barcode image file.

    One way is to make the D&D box visible once I click SAVE button, but I cannot do it. The code is super simple:

    Private Function ShowBox()
    lvDND.Visible = True
    lblDropBarcode.Visible = True
    End Function

    Now, how do I call this? Access' GUI macro screen confuses me, but I tried RunCode and RunMacro and put this function/sub... It does not seem to find it. Maybe the location of the code? The button was generated by Access' wizard.
    Click image for larger version. 

Name:	macro screen.jpg 
Views:	16 
Size:	28.9 KB 
ID:	52683


  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Not many of us use macros. Try this in VBA in the click event of the button:

    ShowBox
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    stingray is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    22
    Quote Originally Posted by pbaldy View Post
    Not many of us use macros. Try this in VBA in the click event of the button:

    ShowBox
    It did not work yesterday, but it worked today without touching anything. I hate Access (it is lack of knowledge on my side), but it is working now.

    Thank you everyone!

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

Similar Threads

  1. Replies: 1
    Last Post: 07-12-2023, 08:24 AM
  2. Replies: 6
    Last Post: 09-18-2020, 09:06 PM
  3. Replies: 5
    Last Post: 07-10-2020, 12:41 PM
  4. Replies: 3
    Last Post: 07-13-2015, 12:07 PM
  5. Replies: 9
    Last Post: 05-30-2011, 12:08 PM

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