Results 1 to 21 of 21

Thread: Saving images, and more, to a database

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved Saving images, and more, to a database

    I have gone through Beacons tutorial on how to add images to a database.
    I have it all working as he describes.

    What I would like to do, is to be able to add MS Word documents to a database.

    I added this code to the common dialog code in Beacons tutorial:
    vb Code:
    1. .Filter = "Picture Files (*.doc, *.gif, *.jpg) |*.doc; *.gif; *.jpg"
    Which lets me select a .doc file, but when I try to save it I get the error:

    Unable to bind to field or DataMember: 'Picture'

    Picture is the name of the field that stores the actual image.

    Has anybody done this with a word document before?
    Last edited by aikidokid; Apr 25th, 2007 at 01:19 PM.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Saving images, and more, to a database

    I've never tried with an Access database, but I have stored Word documents to an SQL Server databases as BLOB's....does Access support BLOB?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Saving images, and more, to a database

    It does - the data types listed in the tutorial are all BLOBs.

    The issue (if my memory is accurate) is the use of the picture/image control, which can only be used for images.. simply removing that control should remove the error.

    It will not however let you get the file out of the database again.. to do that you need to use code that is not in the tutorial!

    I've written a sub to do it (which unfortunately nobody has given a real comment about) in post 2 of this thread, which will hopefully work for you (if so, I can add it to the tutorial).

  4. #4

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    Quote Originally Posted by Hack
    I've never tried with an Access database, but I have stored Word documents to an SQL Server databases as BLOB's....does Access support BLOB?
    I know nothing about BLOB,s and not that much about Access come to that

    I will have to read up on this.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Saving images, and more, to a database

    BLOB stands for Binary Large Object - basically 'big' data that does not fit into the normal data types (char/varchar/text/memo/...), and/or data which uses "non text" characters that may cause issues (such as Chr(0) ).

    The data type "OLE" in Access is a BLOB (most database systems use different names for it ).

  6. #6

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    Quote Originally Posted by si_the_geek
    I've written a sub to do it (which unfortunately nobody has given a real comment about) in post 2 of this thread, which will hopefully work for you (if so, I can add it to the tutorial).

    Thanks si_the_geek

    I will take a look at this in the next day or two and get back to you on how I get along.

    @si_the_geek

    What do you think about my idea here with regards to actual forms?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Saving images, and more, to a database

    If you are talking about an actual.frm file (presumably for your code store project), that will be fine - just make sure that you also save/restore the .frx file (if it exists) that has the same name as the .frm file. Oh, and you'll probably want to store a list of required components & references for each form too, so you can add them to the project before loading the form.

    I would personally keep the files separate myself tho (thru fear of database corruption destroying all the files), but it's up to you.. I know how you like to try out different things!

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Saving images, and more, to a database

    Quote Originally Posted by si_the_geek
    I've written a sub to do it (which unfortunately nobody has given a real comment about) in post 2 of this thread
    I'd never noticed it before. I just saved it as a module, including the modifications for saving the file name, etc. Very nice code. (The project I needed BLOBs for is long gone, and it used jpgs so the changes weren't really needed, but it's in the code library, just in case.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    Quote Originally Posted by si_the_geek
    I would personally keep the files separate myself tho (thru fear of database corruption destroying all the files), but it's up to you..
    So, save the forms\project to a seperate folder, in say the C:\ProgramFiles\CodeLibrary folder, and save the file path to be opened from clicking on the node?
    Then what, open the form with Shell.Execute straight into a new project in VB6?

    Quote Originally Posted by si_the_geek
    I know how you like to try out different things!
    Yes I do, but then again, I do want to try to do this the best, safest way also
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Saving images, and more, to a database

    You can't add a form to a compiled project at runtime, so I'm still not certain what purpose you are trying to achieve.

    Am I missing something?

  11. #11

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    Apart from just practising something new, I also want to try and keep some examples of forms.

    Say for example, with this project I am working on at the moment, I have made my own Find\Replace form. Now this was to learn more about string manipulation, but, it could come in handy to use somewhere else.

    Also, sometimes, if I am not sure how to do something, rather than try to work it out in my current project, I create a new form, in a new project to practise what I am trying to achieve.

    Now, having the memory that I have it would be useful for me to keep a working example of this, also with my code, that I hopefully will still be able to understand in 6 months time.

    I am just trying to tie this all in with my learning how to use the Database for the first time. Maybe I am trying to do too much for something that could be tackled an easier way.

    As you know, I am always open to suggestions because the vast majority of you out there in VBF land have a lot more experience than me with coding.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Saving images, and more, to a database

    Just for clarification Hack, it's part of the code library - so is purely for 'design' time usage.
    Quote Originally Posted by Al42
    I'd never noticed it before. ...
    I haven't tested it properly (only quickly against Access) so didn't want to make it too public before other people check it!

    I hope it comes in useful.
    Quote Originally Posted by aikidokid
    So, save the forms\project to a seperate folder, in say the C:\ProgramFiles\CodeLibrary folder, and save the file path to be opened from clicking on the node?
    Then what, open the form with Shell.Execute straight into a new project in VB6?
    That sounds like the best idea to me.. putting it all into a database is more work, and less reliable - which for something like this (storing something that could save you hours/days later) is not ideal.

    To be honest this kind of work is pretty rare (I've only used it a couple of times myself) and is of limited use, so unless there are other types of files you want to store, you would probably be better off focussing on other aspects of working with databases, or other kinds of programming.

    Quote Originally Posted by aikidokid
    Now, having the memory that I have
    I think all of us in this thread are the same way.. and I think I'm the youngest of us by about 10 years!

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Saving images, and more, to a database

    Quote Originally Posted by aikidokid
    Say for example, with this project I am working on at the moment, I have made my own Find\Replace form. Now this was to learn more about string manipulation, but, it could come in handy to use somewhere else.
    Just save the source code as text, with comments about the controls you placed on the form, and any references you have to add to make it work. (There's nothing else in a form file that you have to save.) Most snippets of the type you're talking about are pretty small.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Saving images, and more, to a database

    Quote Originally Posted by si_the_geek
    To be honest this kind of work is pretty rare (I've only used it a couple of times myself) and is of limited use
    I did a program for a security firm that wanted to save mug shots in a single file so they could copy the system to different computers easily. They wanted just one .exe file, but I wasn't about to write them a new operating system, so an .mdb file and BLOBs.
    I think all of us in this thread are the same way.. and I think I'm the youngest of us by about 10 years!
    My gray hairs have whiskers, so it's probably more than that between you and me. (I can remember the day FDR died.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  15. #15

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    Quote Originally Posted by aikidokid
    Thanks si_the_geek

    I will take a look at this in the next day or two and get back to you on how I get along
    I have had a go and posted in the original thread
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  16. #16

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    This is now resolved.

    I have added the code from a form to the database, along with it's name etc.
    I have then added a MS Word document to a dedicated folder.
    Then when the treeview node is selected, it shows the code and opens the document in word, if one exists.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  17. #17

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    I have used this code to do the above, which works fine.
    I just wanted to check that, if no file was found to be opened, this code is still ok.

    I have tried it and it seems to be, but just checking

    vb Code:
    1. 'see if there is a picture (word document) to open
    2.         strSQL = "SELECT Code_Description, DocumentTitle FROM tbl_Code"
    3.         strSQL = strSQL & " WHERE DocumentTitle = '" & strNameExtension & "'"
    4.         rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
    5.        
    6.         'if value in field found, open word document.
    7.         ShellExecute Me.hwnd, "open", App.Path & "\Forms\" & strNameExtension, vbNullString, "", SW_SHOWNORMAL
    8.        
    9.         Set rs = Nothing
    10.         cn.Close
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  18. #18
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Saving images, and more, to a database

    I'm back to this thread at last... one thing that jumps out at me is that you aren't checking for rs.EOF, which you should always do when reading data from a recordset - but on further inspection, you aren't reading from it anyway, so presumably the recordset code you posted is unnecessary (you just need strNameExtension to be valid).

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Saving images, and more, to a database

    I think he would want to open DocumentTitle, not strNameExtension.Text. In "ThisDocument.doc", strNameExtension.Text would be "doc".
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  20. #20
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Saving images, and more, to a database

    You may well be right.. I assumed that it contains the Name and Extension, we'll have to wait and see!

  21. #21

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Saving images, and more, to a database

    Quote Originally Posted by si_the_geek
    one thing that jumps out at me is that you aren't checking for rs.EOF, which you should always do when reading data from a recordset
    I know that as well. oops


    Quote Originally Posted by si_the_geek
    but on further inspection, you aren't reading from it anyway, so presumably the recordset code you posted is unnecessary (you just need strNameExtension to be valid).
    So all I would need from above is:
    vb Code:
    1. 'if value in field found, open word document.        
    2. ShellExecute Me.hwnd, "open", App.Path & "\Forms\" & strNameExtension, vbNullString, "", SW_SHOWNORMAL

    and this is the code you both were wondering about.
    I have a check box that shows when the category 'Form' is selected. If the check box is selected, then I need to save a word document.:
    vb Code:
    1. 'check to see if a picture has to be saved (chkPic.Value)
    2.     If chkPic.Visible = True And chkPic.Value = 1 Then
    3.         .Fields("DocumentTitle").Value = RoutineName & ".doc"
    4.     End If
    I can see how the name strNameExtention may have been misleading
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

Posting Permissions

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



Click Here to Expand Forum to Full Width