Solved

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

Posted on 2016-10-26
7
16 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

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)

Join & Write a Comment

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

747 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

13 Experts available now in Live!

Get 1:1 Help Now