Solved

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

Posted on 2016-10-26
7
32 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 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

696 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