Using datagrid field to open document

dobbs
01-08-2004, 10:44 AM
Hello all,

I have run into a problem with a program I am developing. The purpose of the program is to produce a list of documents along with the document path in a datagrid. What I want to do is to be able to select a document from the datagrid and open it with a command button. I need this list to be able to connect to a .mdb database because it will be updated frequently. Can anybody help me with the code to do this?

I am able to open a document with the command button alone and I am able to list the documents and their paths within the datagrid, but I am having trouble connecting the two. Thanks in advance for any help.

Mike

dobbs
01-08-2004, 03:04 PM
I think that my previous explanation would be better explained with a sample of my code. Here is what I am using to open the document:

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Const SW_SHOWNORMAL = 1

Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
"", "I:\", SW_SHOWNORMAL)
End Function

Private Sub cmdClose_Click(Index As Integer)
Unload Me
End
End Sub

Private Sub Command4_Click()

Dim r As Long, msg As String

r = StartDoc("i:\users\mike r\test.mxd")
open
If r <= 32 Then
'There was an error
Select Case r
Case SE_ERR_FNF
msg = "File not found"
Case SE_ERR_PNF
msg = "Path not found"
Case SE_ERR_ACCESSDENIED
msg = "Access denied"
Case SE_ERR_OOM
msg = "Out of memory"
Case SE_ERR_DLLNOTFOUND
msg = "DLL not found"
Case SE_ERR_SHARE
msg = "A sharing violation occurred"
Case SE_ERR_ASSOCINCOMPLETE
msg = "Incomplete or invalid file association"
Case SE_ERR_DDETIMEOUT
msg = "DDE Time out"
Case SE_ERR_DDEFAIL
msg = "DDE transaction failed"
Case SE_ERR_DDEBUSY
msg = "DDE busy"
Case SE_ERR_NOASSOC
msg = "No association for file extension"
Case ERROR_BAD_FORMAT
msg = "Invalid EXE file or error in EXE image"
Case Else
msg = "Unknown error"
End Select
MsgBox msg
End If

End Sub

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

I did obtain this code from a tutorial that I found online.

This line:

r = StartDoc("i:\users\mike r\test.mxd")

is where I want to replace the code with a SQL statement that will look at the entry in my .mdb file.

It seems that this could work, but I am really a novice and I am sure where to get started. Any help with this would be greatly appreciated.

Thanks,

Mike

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum