?
Solved

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

Posted on 2016-10-26
7
Medium Priority
?
33 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 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

765 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