Attn: Ken Snell - Displaying chemical structures in Access

M

Michele

Hi Ken,

I saw from another posting that you have a Ph.D. in chemistry. I need some
help. I have a database that has over 30,000 chemicals in it. I need to
display chemical structures for each chemical when the user chooses that
chemical.

My first wish would be to draw the structure from the SMILES notation within
Access with a .dll, possibly. So far, the one .dll I do have pops up a new
window with a structure drawn as a windows metafile. Not sure how I would
incorporate that into an access form

Another alternative would be drawing the chemical structures in other
software, such as ISIS or chemdraw and then either pasting the structues into
the database or better putting in a separate folder and then having code
point to that image. I have code to do that. That would take a long time to
create all the structures.

Any help or insight would be extremely appreciated!

Thanks,

Michele Stephenson
 
A

Arvin Meyer

Hi Michele,

Actually, there are 2 Access MVPs with PhD's in Chemistry, Ken and John
Vinson. Your question though may be answered by anyone who knows graphics
with Access .

My suggestion would be to store the path of each chemical's molecular
drawing in the database and the actual graphic on the hard drive. See my
sample database for an example (actually it can set up everything for you
and all you'll need to do is copy the data into your database:

http://www.datastrat.com/Download/Picture2K.zip
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access Downloads
http://www.datastrat.com
http://www.mvps.org/access
 
K

Ken Snell [MVP]

Michele -

I yield to Arvin's superior knowledge about graphics in ACCESS, which is an
area that I have not yet tackled.
 
J

John Vinson

Actually, there are 2 Access MVPs with PhD's in Chemistry, Ken and John
Vinson. Your question though may be answered by anyone who knows graphics
with Access .

.... better than I can answer it! I've worked with SMILES and with
ISIS/Base - ISIS/Draw, but it's been years and I never did work with
an Access interface.

Thanks Arvin and Stephen, marking your posts for retention!

John W. Vinson[MVP]
 
M

Michele

Stephen,

Thanks for the suggestion. I was able to get the DLL to draw the structure,
but of course, I have hit a snag...

The DLL was written so that the first argument you pass it is the SMILES
notation and the second is the path. On my form, it gets the SMILES notation
and the path and then I call the DLL in a module, it then draws the structure
and I have another function that puts that path into .picture = strImagePath,
it then puts the image nicely into the Image Control.

So i choose the next SMILES notation and it tries to draw the structure and
put on hard drive, but it can't replace the existing one because it is open.
What if I clear the image control.. I was able to clear the Image Control,
but that didn't help, so next I currently have the code drawing to two
different paths and going back and forth between them thinking that when the
second image is drawn and placed in image control, it would release the first
image, but it doesn't. The only way I have been able to delete an image from
the hard drive is by exiting out of access, even closing the form doesn't work

How do I release, free, clear the image from the image control? Below is my
code that I currently am using. Thanks for your help and expertise!

michele

FORM

Private Sub Command0_Click()
Dim XX As String
Dim ZZ As String
Dim picture1 As Boolean

Me.imagepath.SetFocus
stateofpicture = Me.imagepath.Text

If stateofpicture = "" Then
picture1 = True
End If

If stateofpicture = "c:\michele\smile1.wmf" Then
picture1 = False
Else
picture1 = True
End If

If picture1 = True Then
XX = Me.SMILES
ZZ = "c:\michele\smile1.wmf"
Me.imagepath = ZZ

'tried to delete the image that is not in image control, get
permission error
' Dim fs As Object
' Set fs = CreateObject("Scripting.FileSystemObject")
' fs.deletefile "c:\michele\smile2.wmf"

'this calls the DLL to draw structure
Call AaaSmiTest(XX, ZZ)

Else
XX = Me.SMILES
ZZ = "c:\michele\smile2.wmf"
Me.imagepath = ZZ

Call AaaSmiTest(XX, ZZ)

' Dim fs1 As Object
' Set fs1 = CreateObject("Scripting.FileSystemObject")
' fs1.deletefile "c:\michele\smile1.wmf"

End If
End Sub

MODULE CODE

Option Compare Database
Option Explicit

Public Declare Function smi2wmf Lib "Smiconv.dll" ( _
ByVal XX As String, ByVal ZZ As String) As Integer

Public Function AaaSmiTest(ByVal XX As String, ByVal ZZ As String) As Integer

'get Bad DLL convention error due to calling convention within DLL itself
On Error Resume Next

AaaSmiTest = smi2wmf(XX, ZZ)

Call setImagePath

End Function

Function setImagePath()
Dim StrImagePath As String
Forms!test.PictureType = 1
StrImagePath = Forms!test.imagepath.Value
Forms!test.image_structure.Picture = StrImagePath
End Function
 
M

Michele

Stephen,

Thanks for you reply. I still can't get it to work, but after much trial
and error, I have narrowed the problem down that once the image control opens
a .wmf file, it won't delete it until i exit out of access. I can delete
..jpg and .bmp file. So I did a test of just opening a .wmf file in a image
control on a click event and then going to the folder and trying to delete
the file and it still won't work. I tried adding in setting the picture
property to null and then adding DoEvents. i have never used this before, so
wasn't sure if I am using it correctly or not. I saw that you posted some
other code on another newsgroup for drawing and then closing a WMF file.

How can I email you the .dll?

Thanks..
Michele

Here is my code for just opening a WMF file in an image control
Function setImagePath()
Dim StrImagePath As String
Me.PictureType = 1
StrImagePath = "c:\michele\smile2.wmf"
Me.image_structure.Picture = StrImagePath
End Function

Private Sub Command0_Click()

Call setImagePath

Me.image_structure.Picture = ""

DoEvents

End Sub
 
M

Michele

Stephen,

I got to work!! I used your code from A2KLoadJpegGifVer30D.mdb that
converts the metafile to an enhanced metafile and then displays it in the
form image control. It took me a while to figure out which part of the code
I needed..about wore out my F8 key :). I finally just brought over the
entire module and I start at FLoad Picture. I hard code the string from the
structure into StrFileName and then it goes..For some reason though I can't
get the autosize boolean to go to true for the image control to resize
itself, but it doesn't seem to affect the displaying of the image.

We don't have the code for the initial creating of the structure or I would
send it to you. To bypass the first error from the dll I just put in on error
resume next. It still gives me an Bad DLL calling convention (error 49).
One of the programmers here who uses this DLL in a C program says he think
has do do with the CDecl statement and not using the standard StDCall
convention. Since I have never written a DLL it doesn't make sense to me.
Also, the dll only makes .wmf files so I couldn't go that route of creating
an enhanced metafile straight out.

Thank you so much for all your help. Now someone here doesn't have to draw
30,000 chemical structures and I learned some more programming:)

michele
 
M

Michele

Hi Stephen,

Thought you were done with this:)

I showed my project manager your email about giving me a raise and he
laughed! Another question/problem regarding this. I forgot in my excitement
that I also have to display the image on various reports and print that
image. In doing some testing, the only way I can get it to work is to call
the FLoad Picture function and reconvert the image again and the arraymeta
will point to the report image structure instead of the forms image
structure. If I set the path of the image structure in the report to the WMF
file it locks itself like before.

Questions..
1. when the code converts the WMF file to and EMF file, I assume it is doing
this only in memory, because the file extension doesn't change. correct?

2. Is there a way in your FLoad Picture Function for the program to know
where this function was called from? Either the main search form which
initially displays the image or from a report. I have about 8 or 9 reports
that will need to display and print this structure. Can I somehow assign a
value to the click event and then have a case function with values so
arraymeta can be assigned to either the form or one of the reports. Can you
tell I haven't been programming too long:)

thisis the part of the code I am talking about.

'ctl.Picture = arrayMeta
'first one for forms and second for one of the reports. commented one or the
' other out for testing
Forms!SearchForm.image_structure.PictureData = arrayMeta
Reports!ChemPropertiesReport.mypicture.PictureData = arrayMeta

Thanks for your help.
michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top