Solved

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

Posted on 2016-10-26
7
22 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
  • 4
  • 3
7 Comments
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 500 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 30

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 30

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now