Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2007
    Posts
    25

    Unanswered: attach oleobject from cmd button

    Using Access 2000

    I've been searching for 3 days now for a solution, but to no solution quite yet. I decided I would ask those who are more knowledgable than me in these matters....

    I have an AddressBook table which has a signature which is no more than a JPG as an OLEObject. Currently have to go to the table directly and go Insert - Object then it will allow it.

    I am trying to create a command button from the Address Book Form which will say "Attach Signature" 98% of the entries will not have signatures, but need the ability to add them without going to the table to do so.
    Images would go directly into the DB, not linked to.

    I am assuming a bit of VBA will be required and this is where I'm lacking. Under normal operation going Insert - Object, the initial box that comes up is "Insert Object" which you then have to select create from file. I'd rather not confuse anyone, so I'd rather just a simple path box so you can type the path to the file or click the browse button. It will always be a JPG, so file types shouldn't matter.

    Could someone please give some insite and/or code that would do this from a command button on click?

    thanks,

    RJ

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Take a look in the Code Bank located at the top of this forum list. I believe Paul (pkstormy) has but examples in there of how to access a file dialog box so that users can select files.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Actually, I posted it
    George
    Home | Blog

  4. #4
    Join Date
    Dec 2007
    Posts
    25
    Quote Originally Posted by georgev
    Actually, I posted it
    Thanks, but unfortunantly that example db doesn't work under 2000.

    Following up. I found this and this got me half way to where I need to be. I setup the main code as a module as I believe I'll end up using this in more than one place. Then I used this.....

    Code:
    Private Sub Command80_Click()
    
    Dim strFilter As String
    Dim strInputFileName As String
    
    strFilter = GetFile.ahtAddFilterItem(strFilter, "Windows Bitmap (*.BMP)", "*.BMP")
    strInputFileName = GetFile.ahtCommonFileOpenSave( _
                    Filter:=strFilter, OpenFile:=True, _
                    DialogTitle:="Please choose a bitmap image for signature...", _
                    Flags:=GetFile.ahtOFN_HIDEREADONLY)
    End Sub
    ...in the "onClick" for the button. To select the file it works beautifully, but obviously there is no code there with what to do with the file after it's been selected. Still struggling with this one...

    Simply put, it needs to go in table named "AddressBook" into the cell for the current record under "Signature". "Signature" is an oleObject field.

    I believe, strInputFileName is returning the file, but I could be wrong. I'm finding VBA is a bit harder to read and understand than PHP, which is where I do most of my work in this realm.

    If I could get that, then I'll have this section licked.

    Thanks for any help provided.

    RJ

    _________________
    EDIT:

    Searching through the code bank, I found that PKSTORMY did post the browse function, which coincidently is the exact same code I found covered above, but it stopped short of actually having the import code I'm looking for.

    I guess the key thing I'm looking for is....

    DoCmd.Import.The.File.Where.I.Need.It.To.Go. LOL UGH!

    Thanks,
    RJ

    ____________________________
    Edit:

    I think I'm REAL close.....

    This is what I've gotten in just a short time....

    I found this bit of code which I'm trying to merge with the above code to get to a solution....

    Code:
    Dim OLEFileName As String
    OLEFileName = MyBrowsForFileFunction("MyStartLocation","MyFilter") ' Or whatever function you prefer.
    If OLEFileName <> "" Then 
       Me.myOLEBoundObjectControl.OLETypeAllowed = acOLEEmbedded
       Me.myOLEBoundObjectControl.SourceDoc = OLEFileName
       Me.myOLEBoundObjectControl.Action = acOLECreateEmbed
    End If
    Me.theControlThatInitiatedThis.SetFocus
    What I changed it to merging with the browsing code....

    Code:
    Private Sub Signature_Click()
    Dim strFilter As String
    Dim strInputFileName As String
    
    strFilter = GetFile.ahtAddFilterItem(strFilter, "Windows Bitmap (*.BMP)", "*.BMP")
    strInputFileName = GetFile.ahtCommonFileOpenSave( _
                    Filter:=strFilter, OpenFile:=True, _
                    DialogTitle:="Please choose a bitmap image for signature...", _
                    Flags:=GetFile.ahtOFN_HIDEREADONLY)
                    
    
    If strInputFileName <> "" Then
       Me.Signature.OLETypeAllowed = acOLEEmbedded
       Me.Signature.SourceDoc = OLEFileName
       Me.Signature.Action = acOLECreateEmbed
    End If
    Me.Signature.SetFocus
    
    End Sub
    However it is bombing on this line....

    Me.Signature.Action = acOLECreateEmbed

    Giving Runtime error '2777': The class argument in the CreateObject function of the Visual Basic proceedure you're trying to run is invalid.

    I'm so close I can taste it. Any assistance in merging the two or a better way of embedding would be appreciated. Thanks so much.

    RJ
    ________________________
    Hopefully this will be the final edit of this.....

    Found the problem..

    Me.Signature.SourceDoc = OLEFileName

    Oops, was suppose to be

    Me.Signature.SourceDoc = strInputFileName

    This works now and actually embeds...

    Hopefully someone else will benefit from me pulling my hair out. LOL

    Thanks for the help,

    RJ
    Last edited by rjwebgraphix; 12-06-07 at 23:18.

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Quote Originally Posted by georgev
    Actually, I posted it
    There are 2 examples in the code bank. One which georgev posted, uses FSO and requires a reference to the Microsoft Office Object library and one which I posted which does not require the Microsoft Office Object library but instead uses an API.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Ummm. Ya.

    Code Bank. Great place to start. Lots of great examples from both George and Paul. Lots of examples from other members as well.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Hehe, only about 3 from me

    Paul,
    I know this isn't the right place but at least I know you'll read it...
    I've been thinking that we really need to review the code bank and give it a sever tidy up and comment each entry better (and perhaps include a contents!). What do you reckon?
    George
    Home | Blog

  8. #8
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I agree fully George! I've been just posting examples mainly so I could download them as I need them where ever I'm at (it's easier for me to just download them verses copy them to and from my usb key.) I often find myself digging through the examples to find stuff and it would be really nice to have some kind of structure and guidelines since I'm probably the most to blame for not organizing them! (I'm extremely grateful though that I'm allowed to post them.)

    I don't know who all else has been testing them (I know I've downloaded all the examples from everyone else and keep them handy.) Isn't Pootle in charge of the Code bank? Whoever is, they've haven't cracked the whip on me yet but I'm been thinking the same as you and agree that someone should set some rules. I guess I like freedom in one way and I don't like the freedom in another way (if that makes any sense.) It would be nice if we could eliminate answering the same questions in posts over and over again by having people go to the code bank. From what I've seen, I think on the average, 30 users view the uploads in each thread. I haven't gotten much feedback though from anyone whose downloaded my examples on if they were helpful or not.

    I think Loquin had some good suggestions for organizing them but I don't think we've ever really discussed it fully. I think we should all get together some place (like Hawaii or Cancoon or Vegas) and chat for a week. Do you think there's any chance we could get some donations from somewhere to buy our tickets and rooms?

    My thoughts are that it would be nice to have a menu type system as I've seen on other sites. I'd hate to see a long process made where the upload needs to be qc'd first before uploading but maybe we should have a section where it's posted for review and then goes to the Code bank. Something where a few of us moderators would have to test and ok them before going to the code bank. I'm game for helping testing any uploads. I don't see a lot of uploads by users and I wish we could establish something to encourage more user uploads of examples.

    I've got a few dozen more examples I'd like to upload but I haven't yet as I don't have comments and the code is messy (but does the trick.) I wouldn't mind uploading them in a "for review" or "untested" type section before they go to the Code bank and are organized. What do you think?

    Quick question, have you noticed that when you click on the number in the thread with the example and it pulls up the post in a popup window, you only have a few seconds to copy the link before it dissappears? It's been aggravating the heck out of me as I want to copy the link to post in the thread for the user.

    Lastly, I'm not the best at writing the description about the upload and I'd be interested in seeing what others would write about my examples and what they do.
    Last edited by pkstormy; 12-09-07 at 03:16.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •