Make sure its not being used by another instance of Visio.
If still not working, then try saving your project and rebooting
your system. Then try. Maybe there is a process still attached to
the drawing from any previous debugging?
Printable View
Make sure its not being used by another instance of Visio.
If still not working, then try saving your project and rebooting
your system. Then try. Maybe there is a process still attached to
the drawing from any previous debugging?
ok i will give that a shot. here is the code for my whole thing maybe something in there has some thing to do with it.
VB Code:
Option Explicit Public Rs As New ADODB.Recordset '****************************************** 'this is sub is for getting the pics 'off of the DB Private Sub cmdGet_Click() Dim Srs As ADODB.Recordset Set Srs = New ADODB.Recordset Dim sql As String ArrestNum = UCase(InputBox("Enter Arrester Number", "Arrester number")) sql = "SELECT * FROM Drawing WHERE ArresterNumber = '" & ArrestNum & "'" Srs.Open sql, DBConn, adOpenDynamic, adLockOptimistic Dim mstream As ADODB.Stream Set mstream = New ADODB.Stream 'mystream is binary because it will be retrieved as a binary from the DB mstream.Type = adTypeBinary mstream.Open 'the caption that goes with the picture is loaded into label1 Label1.Caption = CStr(Srs.Fields("ArresterNumber").Value) 'The stream is "writing" what is in the Drawing field of the table mstream.Write Srs.Fields("Drawing").Value 'the stream saves it to a temporary file mstream.SaveToFile "C:\Temp.jpg", adSaveCreateOverWrite 'Image1 laods the picture from the temporary file Image1.Picture = LoadPicture("C:\Temp.jpg") FName = "C:\Temp.jpg" 'The file is then destroyed as it is no longer needed Kill ("C:\Temp.jpg") mstream.Close Set mstream = Nothing Srs.Close Set Rs = Nothing End Sub '********************************************* 'This sub is for loading a picture from 'a saved location on the network i.e. a folder Private Sub cmdLoadFile_Click() With Dialog .DialogTitle = "Select Picture to Open........." .ShowOpen FName = .FileName Image1.Picture = LoadPicture(.FileName) End With End Sub '******************************************* 'This sub is for saving the pics to the DB Private Sub cmdSave_Click() Dim sql As String 'ArrestNum is capitalized so that retrieving will be smoother ArrestNum = UCase(InputBox("Enter Picture Name", "Name this Picture")) sql = "SELECT * FROM Drawing" Rs.Open sql, DBConn, adOpenDynamic, adLockOptimistic Dim mystream As ADODB.Stream Set mystream = New ADODB.Stream 'mystream is binary because it will be saved as binary in the DB mystream.Type = adTypeBinary mystream.Open 'adding a new record With Rs .AddNew 'The caption for the picture !ArresterNumber = ArrestNum 'loads the picture from the file into mystream Debug.Print FName mystream.LoadFromFile FName 'reads the picture into the Drawing field of the DataBase and updates the DB !Drawing = mystream.Read .Update End With MsgBox "UPDATED AND WORKED" mystream.Close Set mystream = Nothing Rs.Close Set Rs = Nothing End Sub Private Sub cmdVisio_Click() Dim vso As Visio.Application Dim vsd As Visio.Document Dim vsp As Visio.Page Dim shp1Obj As Visio.Shape Debug.Print FName Set vso = New Visio.Application Set vsd = vso.Documents.Open("H:\SAMDrawing\SAMDraw\Test.vsd") vso.Visible = True Set vsp = vsd.Pages.Item(1) 'Change to reflect the path to a image on your system Set shp1Obj = vsp.Import("H:\SAMDrawing\MountingW2Plates.bmp") shp1Obj.CenterDrawing '"H:\SAMDrawing\MountingW2Plates.gif" End Sub '*************************************** 'The form loads with a connection the DB Private Sub Form_Load() Call makeConnection End Sub
i tried it out and it didn't work. so i don't think that it has any thing to do with my other code. i'm still trying to figure some thing else out.
I dont think any of the other code is affecting the Visio part, but
what is the exact version you are running? I am running 2002 SP-2
10.0.5110. I tried my code with a .bmp file on a network share
and it still worked.
:confused:
Maybe it has something to do with the image not being accessible
or maybe its not finished being loaded from the other procedure
which retrieves the image from the db.
i am using Visio 2000 6.0.0.3 so your are way more current than me. i have tried to "Hardwire" the picture in there that way none of my other code will have any affect on it. i have to get pics off the DB, but i figured that i should first learn to put pics in there with VB6 first then try to get them off the DB.
i've been working with it a little more and have discovered some thing rather interesting.
when i try to import a bitmap(bmp) then i get an error saying
"Visio can't open the file for reading"
but when i try to open a JPEG(jpg) or a GIF(gif) i get an error saying
"An Error occured. Visio is unable to complete importing"
Try using an image from your system that is not being pulled out
from the database. It may be that there could be a process still
on the image being pulled from the db. Just use a samlpe picture
like your desktop wallpaper or anything else and see if it works.
that is what i have been using. in the future i will try and get them from the DB, but now i am just hardwiring the value in the program
Set shp1Obj = vsp.Import("H:\SAMDrawing\MountingW2Plates.bmp")
Instead of using a mapped drive, try using a copy of the picture
on your C drive. It must be something specific to Visio 2k?
i got the same error, changed it to a pic on the C: drive. i have been looking @ the help files all morning long and i still have not found any thing.
Try doing an Office Update to see if there is a hotfix or sp for Visio 2k.
It has to be something because the code works fine in 2002.
:confused:
i'll see what i can do about that, i am only on a small node and can't do that stuff i think, let me look tho. if not i think maybe i'll have to try the drop method.
is this how i would tell if i need a hotfix or sp?
No, use the office update website. Its the same as windows update
but for office. Click on "Check for Updates" link to start.
Office Update
i went the website but i can not follow the link to the officeupdate because i am @ work. so do you think that you could post the address not as a hyperlink?
Code:http://office.microsoft.com/search/redir.aspx?AssetID=ES790020331033&Origin=HH011497461033&CTT=5
k i looked and there weren't any that were needed for Visio. there were some other things in there but nothing about Visio.
do you think that it is because i am using ado in the program?
??? But even I came up with one for Visio XP.
Visio 2002 Security Update: KB831932
r u on a large network?
No, small one with PDC, BDC, T Server, File Server, and
about a dozen workstations.
oh well man i donno i'm gonna try and work this out a little bit more and if tomorrow by noon i haven't made progress then i think i need to find some other way to get the picture into Visio(the bosses are getting impatient). are you putting that code in a VB6 form? or in the vba window in Visio?
Code is in a VB form. What about automating the retrieval of the
image to the temp dir and then automate Visio "manually" to
import the images? Kinda like doing a FindWindow,
FindWindowEx, and SendMessage. Send the key sequence to
import the image?
i'm not sure i understand what you are talking about, i have never used that method. maybe you could show me an example?
i was able to draw a rectangle in visio via the VB application! so i can draw things, i just have to figure out why i can't open a picture.
I GOT IT! i got it! but it only works with jpeg files right now i have to work with it some more so that i can get any type of file in there. thanx for all the help so far man. i've included it zipped up so you can look @ if you want to.
forgot the project
something is up with the attatchments here and i can't zip the project up. if you want to see code let me know.
disregard the last post
Dubya007, the zip is corrupted or ??? It says it not a valid archive
and it has now files in it, but its 449kbs. Can you rezip and
repost? So glad to hear that its partially working for you!
Or just post the code thats concerned.
Thanks.
here you go
i donno if that last one worked either. not sure what is up with winzip here so here is the code that is concerned.
VB Code:
Dim shape1 As Visio.Shape Debug.Print FName Set VisioApplication = New Visio.Application Set VisioDocument = VisioApplication.Documents.Open("H:\SAMDrawing\SAMDraw\Test.vsd") VisioApplication.Visible = True Set VisioPage = VisioDocument.Pages.Item(1) 'Change to reflect the path to a image on your system Set shape1 = VisioPage.Import(FName) 'shape1.CenterDrawing Kill (FName) Debug.Print "Killed " & FName
Looks like the same code? As long as its working.
:)
yeah there are some diffferences in there but it works. (there is a God). i was also able to make it to where you can import more than one picture. i need to find out how to position them on the page now.