Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS Access Image Control Split database display image on focus refresh or requery help!

Posted on 2016-10-26
7
Medium Priority
?
35 Views
Last Modified: 2016-11-01
I have a split database and I have a image control that when I click onto the next record the image doesn't requery or refresh to the new image.

This is my Forms On Current Code:

Private Sub Form_Current()
    
    Private Sub Form_Current()
    Call SetFormAllowAdditions(Me!sbfrmProducts.Form, 4)
    
    On Error GoTo ExitProc
    Dim ImagePath As String
    
   
    ImagePath = GetProductImageFilePath & Forms!frmSkusEntry!sbfrmProductImages.Form!ProductImageFileNm

    If Len(Forms!frmSkusEntry!sbfrmProductImages.Form!ProductImageFileNm) > 0 And Len(Dir(ImagePath)) > 0 Then
        Image126.Picture = ImagePath
    Else
        Image126.Picture = ""
    End If
    
ExitProc:
    Exit Sub
ErrProc:
    Select Case Err.Number
        Case Else
            Resume ExitProc
    End Select
End Sub

Public Function GetProductImageFilePath() As String
    GetProductImageFilePath = GetDBPath & "images\"
End Function


    Public Function GetDBPath() As String
    GetDBPath = Replace(CurrentDb.TableDefs("Assemblies").Connect, ";DATABASE=", "")
'Remove db name
GetDBPath = Left(GetDBPath, InStrRev(GetDBPath, "\"))

End Function

Open in new window



ADD IMAGE BUTTON BROWSE TO FILE AND GET FILENAME CODE:

Public Function AddLocalImagePath() As Variant
Dim strImagePath As String

    strImagePath = GetFile_Browse
    
    If Me.NewRecord Then
        Me!ProductImageLocalPath = strImagePath
         Me!ProductImageFileNm.Value = Dir$(strImagePath)
          DoCmd.GoToControl "sbfrmProductImages"
    Else
          DoCmd.GoToControl "sbfrmProductImages"
         DoCmd.GoToRecord , , acNewRec
        Me!ProductImageLocalPath = strImagePath
       Me!ProductImageFileNm.Value = Dir$(strImagePath)
    End If
    
End Function

Open in new window



I need someway of a GotFocus Event Code on the subform sbfrmProductImages to repopulate the Image126 Controller on the Main form when I click on the record row.

Thank you!
0
Comment
Question by:Dustin Stanley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 31

Assisted Solution

by:hnasr
hnasr earned 2000 total points
ID: 41862106
It is hard to understand the problem from just VBA code.
If you can reproduce the issue in a single database, upload to check. Explain the required output.
0
 

Author Comment

by:Dustin Stanley
ID: 41862468
db105.jpg
In the photo I have attached there is a image control on the mainform with a school bus in it. This image control is called "Image126".

Image126 knows which picture to display because of the VBA code:

Call SetFormAllowAdditions(Me!sbfrmProducts.Form, 4)
    
    On Error GoTo ExitProc
    Dim ImagePath As String
    
   
    ImagePath = GetProductImageFilePath & Forms!frmSkusEntry!sbfrmProductImages.Form!ProductImageFileNm

    If Len(Forms!frmSkusEntry!sbfrmProductImages.Form!ProductImageFileNm) > 0 And Len(Dir(ImagePath)) > 0 Then
        Image126.Picture = ImagePath
    Else
        Image126.Picture = ""
    End If
    
ExitProc:
    Exit Sub
ErrProc:
    Select Case Err.Number
        Case Else
            Resume ExitProc
    End Select
End Sub

Public Function GetProductImageFilePath() As String
    GetProductImageFilePath = GetDBPath & "images\"
End Function


    Public Function GetDBPath() As String
    GetDBPath = Replace(CurrentDb.TableDefs("Assemblies").Connect, ";DATABASE=", "")
'Remove db name
GetDBPath = Left(GetDBPath, InStrRev(GetDBPath, "\"))

End Function

Open in new window



I place the information into the table called "ProductImages" which has fields "ProductImageFileNm" and "ProductImageLocalPath" in the subform "sbfrmProductImages" with the Add Image Button next to Image126 in the mainform using code:

Public Function AddLocalImagePath() As Variant
Dim strImagePath As String

    strImagePath = GetFile_Browse
    
    If Me.NewRecord Then
        Me!ProductImageLocalPath = strImagePath
         Me!ProductImageFileNm.Value = Dir$(strImagePath)
          DoCmd.GoToControl "sbfrmProductImages"
    Else
          DoCmd.GoToControl "sbfrmProductImages"
         DoCmd.GoToRecord , , acNewRec
        Me!ProductImageLocalPath = strImagePath
       Me!ProductImageFileNm.Value = Dir$(strImagePath)
    End If
    
End Function

Open in new window


ProductImageFileNm = File Name Only

ProductImageLocalPath = Full Path to the file (***PLEASE IGNORE THIS FIELD AS IT IS NOT THE TRUE PATH. JUST THE PATH FROM THE USER TO THE FILE THEY CHOSE***)

In the Main Larger Code it finds the database backend path and concatenates the database backend path and ProductImageFileNm together to create the true full path for Image126 to display.

Now when I add multiple images which is multiple rows (Records) the photo in Image126 doesn't change when I click on the next record in the subform sbfrmProductImages.

Somewhere somehow something has to requery or refresh (Not sure which one) for Image126 to change the image to what current record I am focused on.

I hope that helps and thank you for time.
0
 

Accepted Solution

by:
Dustin Stanley earned 0 total points
ID: 41862571
Ok I got it!

I had to place this in my sbfrmProductImages ONCURRENT event:

Private Sub Form_Current()
       
    On Error GoTo ErrProc
    Dim ImagePath As String
    
  
    ImagePath = GetProductImageFilePath & Forms!frmSkusEntry!sbfrmProductImages.Form!ProductImageFileNm
    
    If Len(Forms!frmSkusEntry!sbfrmProductImages.Form!ProductImageFileNm) > 0 And Len(Dir(ImagePath)) > 0 Then
        Forms!frmSkusEntry!Image126.Picture = ImagePath
    Else
        Forms!frmSkusEntry!Image126.Picture = ""
    End If
    
ExitProc:
    Exit Sub
ErrProc:
 MsgBox "ERROR"
    Select Case Err.Number
        Case Else
            Resume ExitProc
    End Select
End Sub

Open in new window

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 31

Expert Comment

by:hnasr
ID: 41862642
Dustin Stanley
It is a relief when you figure out your solution to the problem.
It will be highly appreciated, by future visitors of this question,  if you add a short comment summarizing the solution..
0
 

Author Comment

by:Dustin Stanley
ID: 41862688
summarizing the solution

I had to place the same code from my mainform oncurrent event into my subforms oncurrent event when multiple product images were available in my subform and used with a single main form Image Control.
0
 
LVL 31

Expert Comment

by:hnasr
ID: 41862842
Thank you.
0
 

Author Closing Comment

by:Dustin Stanley
ID: 41868084
I received no response but from one person who wanted me to upload a DB because it was hard to understand the problem but at least someone responded. I then figured it out on my own! Thank you hnasr!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question