|
-
Apr 23rd, 2007, 12:58 PM
#1
Thread Starter
Frenzied Member
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:
.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.
-
Apr 23rd, 2007, 01:43 PM
#2
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?
-
Apr 23rd, 2007, 02:00 PM
#3
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).
-
Apr 23rd, 2007, 02:09 PM
#4
Thread Starter
Frenzied Member
Re: Saving images, and more, to a database
 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.
-
Apr 23rd, 2007, 02:16 PM
#5
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 ).
-
Apr 23rd, 2007, 02:28 PM
#6
Thread Starter
Frenzied Member
Re: Saving images, and more, to a database
 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?
-
Apr 23rd, 2007, 03:21 PM
#7
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!
-
Apr 23rd, 2007, 04:39 PM
#8
Re: Saving images, and more, to a database
 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
-
Apr 24th, 2007, 11:04 AM
#9
Thread Starter
Frenzied Member
Re: Saving images, and more, to a database
 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?
 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
-
Apr 24th, 2007, 11:25 AM
#10
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?
-
Apr 24th, 2007, 11:38 AM
#11
Thread Starter
Frenzied Member
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.
-
Apr 24th, 2007, 02:18 PM
#12
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.
 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. 
 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.
 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!
-
Apr 24th, 2007, 05:18 PM
#13
Re: Saving images, and more, to a database
 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
-
Apr 24th, 2007, 05:24 PM
#14
Re: Saving images, and more, to a database
 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
-
Apr 25th, 2007, 09:32 AM
#15
Thread Starter
Frenzied Member
Re: Saving images, and more, to a database
 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
-
Apr 25th, 2007, 01:12 PM
#16
Thread Starter
Frenzied Member
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.
-
Apr 25th, 2007, 01:22 PM
#17
Thread Starter
Frenzied Member
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:
'see if there is a picture (word document) to open
strSQL = "SELECT Code_Description, DocumentTitle FROM tbl_Code"
strSQL = strSQL & " WHERE DocumentTitle = '" & strNameExtension & "'"
rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
'if value in field found, open word document.
ShellExecute Me.hwnd, "open", App.Path & "\Forms\" & strNameExtension, vbNullString, "", SW_SHOWNORMAL
Set rs = Nothing
cn.Close
-
Apr 30th, 2007, 03:01 PM
#18
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).
-
Apr 30th, 2007, 04:08 PM
#19
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
-
Apr 30th, 2007, 04:11 PM
#20
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!
-
May 1st, 2007, 10:21 AM
#21
Thread Starter
Frenzied Member
Re: Saving images, and more, to a database
 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
 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:
'if value in field found, open word document.
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:
'check to see if a picture has to be saved (chkPic.Value)
If chkPic.Visible = True And chkPic.Value = 1 Then
.Fields("DocumentTitle").Value = RoutineName & ".doc"
End If
I can see how the name strNameExtention may have been misleading
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|