Results 1 to 3 of 3
  1. #1
    norseman's Avatar
    norseman is offline Novice
    Windows 8 Access 2016
    Join Date
    Apr 2016
    Location
    Oregon
    Posts
    22

    I want a Command button on a form to open a new window with an .jpg image displayed– Using VBA

    I have a database of high value items and the database currently lists all the pertinent data about the items. The primary display of all items is a continuous form.

    For insurance reasons, I would like to add a picture for each item. I want to have a button at the end of each record line that I can click and have the correct picture displayed in a new window.

    I do not want to have a single screen for each item. This would mean I would need to scroll through hundreds of pages just to get to the one record I want.

    My idea is the following.
    - Store the path and name of each picture in a text field in the database
    - On the main form have a button that when selected passes the value stored in the Picture field to a report
    - The report opens in a new window, displaying the picture of the item.
    - The report would also have a close button

    Right now, I have the following set up

    1. The primary database (Master_Table) contains a text field (Picture) were the full path and picture name is stored.
    2. On the main form (Main_Form), I have a command button (Get_Pic)
    3. I have created a report (ItemPicReport) where I have an image field.

    On the Get_Pic button I have attached the following code to the On Click Event
    Code:
      Private Sub Get_Pic_Click()
        DoCmd.OpenReport "ItemPicReport", acViewReport, , "[R_Picture] =" & Me.[Picture]
      End Sub
    However, this does not open the report and display the picture.

    I have tried naming the image field R_Picture.
    I have tried putting the control source for the picture field to R_Picture
    I have tried putting the control source for the picture to Master_Table.Picture



    I think it comes down to I do not understand how the value I passed in R_Picture gets properly attached to the image field on the report.

    Any help is greatly appreciated.
    Thanks in advance

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Where's your button to open the form?? Don't put the button in the form header - put it in the detail section so that it appears on every row. That section should also contain the textbox with the file path. The button click event should test for txtFilePath being Null or an Empty string and if not, open the form with the image control on it and set the image property to be the path for the chosen record. I know that if you do this on a report, it will know which record the button is on, so I don't see why it won't work for a form.

    Before you go too deep, make the button click event to Msgbox Me.txtSomeBoxThatIsn'tBlank. You should get the correct value in the message for that row. Once that's working, delete that and write the code to open the form instead. I would probably pass the path as the OpenArgs parameter of the DoCmd.OpenForm method although there are other ways. AFAIC they're not as simple. You can then set the picture path property of the image control to whatever you pass to the OpenForm method.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 03-30-2017, 03:20 PM
  2. Replies: 3
    Last Post: 09-26-2015, 06:44 AM
  3. open image file trough a button in form
    By raffi in forum Forms
    Replies: 3
    Last Post: 09-23-2014, 02:49 PM
  4. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 PM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums