Command button to insert OLE Objects (1 Viewer)

rookbird0234

New member
Local time
Today, 08:15
Joined
Jul 16, 2009
Messages
6
I'm trying to create a command button on a form that when clicked will allow a user to select an image to be inserted in an OLE frame bound to an OLE slot in the table the form is based upon. The form tracks a lot of data about part sets for a machine shop and our goal is to add pictures of complicated setups as needed. I am not sure where to begin. I have a code that opens a file dialogue box and inserts a hyperlink to the file the user selects but I don't think that is what I'm looking for here. I'll post that code and maybe some of you folks who tinker with OLE can shed some light on my situation.

Code:
Private Sub btnPic1_Click()
'variable declerations
Dim strFilter As String
Dim strInputFileName As String
Dim strInitDir As String

    'Set the initial directory path
    strInitDir = "H:\Pictures"
  
  'Construct a filter for limiting the file types to those that are desired.
  strFilter = ahtAddFilterItem(strFilter, "Bitmaps Files (*.BMP)", "*.BMP")
  strFilter = ahtAddFilterItem(strFilter, "JPEG (*.JPG)", "*.JPG*")
  strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
  
 'Open the file dialogue for choosing the directory and set strInputFileName
 'to the path of the chosen file.
 strInputFileName = ahtCommonFileOpenSave( _
                Filter:=strFilter, OpenFile:=True, _
                DialogTitle:="Please select a Picture...", _
                InitialDir:=strInitDir, _
                Flags:=ahtOFN_HIDEREADONLY)

  'Here is where the name of the file is passed back to field and set as a
  'Hyperlink.  I want to pass the image into an OLE frame but I don't know
  'What to send back nor how to do the syntax!
  If Len(strInputFileName) > 0 Then
    Me.Pic1 = "#" & strInputFileName & "#"
    Me.Pic1.IsHyperlink = True

  End If
End Sub
Please find a sanitized copy of the database and have a look at frmLatheData. I have begun the work there with the OLE frames but haven't the slightest idea how to code the command buttons. Thanks!
 

Attachments

  • SterileMain_2009-07-17.mdb
    424 KB · Views: 215

Mr. B

"Doctor Access"
Local time
Today, 10:15
Joined
May 20, 2009
Messages
1,932
rookbird0234,

I would suggest that what you really need to do is to just store the path to your pictures and then use an Image control to display your pictures.

Even more important that linking your pictures is the fact that I do not see a primary key (PK) in your tables. This is absoutely essential. The one thing that is critical in creating any database is the table structure of that database. Think of it as the foundation to your entire structure. If the foundation is not correct, the entire structure will fail.

One thing that I think you should really consider (not part of your question) I notice that you have 4 fields in the tblLatheData table (Pic1, Pic2, etc.) what happens if you have 5 pictures for one setup? Consider creating another table just to hold the path and descirpton and other info about pictures. This table would have an AutoNumber type field as a PK for this table and a foreign key (FK) to the tblLatheData table. This will allow you to link the pictures to the Lathe data. Using this method you will not care if there are 20 or even 100 pictures for any one setup. Of course you will have to build your forms to accomodiate this method.

HTH
 

rookbird0234

New member
Local time
Today, 08:15
Joined
Jul 16, 2009
Messages
6
The key is to juggle amount collection with simplicity. I like your thoughts on the database. I had primary keys at one time, but they had to go to allow duplicate part numbers when multiple operations existed. I supposed using auto numbers but I never really knew why I needed a primary key, the data is always going to be related by part number and theoretically operation number in some cases. I guess it would be a good idea, I just don't have a clue how to do in a sensible fashion...yet... I'm trying to solve those like issues as I go along. If you have any suggestions on that subject please let me know, the more I learn about this the better the software will be :)
Thanks
 

Mr. B

"Doctor Access"
Local time
Today, 10:15
Joined
May 20, 2009
Messages
1,932
From your description of your reason for not using PKs (auto Number type fields) I really think you need to reevaluate your database design. You must make sure that you have accounted for all relations in your database. It should like you may still need another table: "but they had to go to allow duplicate part numbers when multiple operations existed".
 

rookbird0234

New member
Local time
Today, 08:15
Joined
Jul 16, 2009
Messages
6
Well, I looked at the matter a little, and I see where it is wise. It's not imperative at this point or in the near foreseeable future that I would want data related on something other than part number but primary keying the tblLatheData, and tblMillData, then linking that to the respective tool data seems like a good idea. Also it might come in kinda handy for working in the picture links also. The first design of this project had more tables, and more seperation, but, it was a mess trying to get it all working together. This was is a little less efficent because it double stores a lot of data, but at the same time it is much less of a headache to work with because everything is in the same place.

It's almost identical to the paper system we are converting from so... that had a little influence on the minimalist approach I guess.

Your urging has been very useful though, I'll do some more reading about Primary keys and relashionships. I understand the filtering because I can see it in the VBA where relationships are just a bunch of lines on a page to me lol.

Thanks again.
 

Mr. B

"Doctor Access"
Local time
Today, 10:15
Joined
May 20, 2009
Messages
1,932
You are welcome. I didn't do much to really help you, but again getting the desing right is what it is all about at this point.

I seem to always get "push back" when I try to get folk to really think through their needs and what the real structure is. You just cannot successfully work with the data if it does not meet the physical requirements. It just will not work.

Good luck with your project.
 

Users who are viewing this thread

Top Bottom