Adding a link to a form...is it possible?

J

jande30

We are creating a database for our special programs. I have a from setup,
however, we want to add a button that, when pushed, will pop up the actual
document. Is there a way to do this?
 
J

jande30

We have a flyer of each program saved as a pdf. We would like the ability to
click on a button and have the pdf version of the specific program to pop up
when in the form.
 
K

Ken Sheridan

There are various ways you could do this, such as following a hyperlink to
the pdf file. Or you could call the Windows API ShellExecute function.
Create the following module in the database:

''''module starts''''
Option Compare Database
Option Explicit

Declare Function ShellExecute& Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nshowcm As Long)

Sub ShellToFile(strPath As String, ByVal lngHwnd As Long)

Dim lngRetVal As Long

lngRetVal = ShellExecute(lngHwnd, "open", strPath, _
vbNullString, CurDir, 1)

If lngRetVal < 32 Then
MsgBox "Unable to open file " & strPath, vbInformation, "Warning"
End If

End Sub
''''module ends''''

and call the ShellToFile procedure in the form's click event procedure like
so:

Dim strPDFPath As String

strPDFPath = <get path to file from somewhere>

ShellExecute strPDFPath, hWnd

Ken Sheridan
Stafford, England
 
J

jande30

I keep getting this error message:

Compile error:

Expected: line number or label or statement or end of statement. It is
highlighting the firs ( in the following:

(ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nshowcm As Long)

Any suggestions?

(I apologize for my lack of knowledge, but I am a beginner.)

Thanks :)
 
B

Bob Quintal

I keep getting this error message:

Compile error:

Expected: line number or label or statement or end of statement.
It is highlighting the firs ( in the following:

(ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String,
ByVal _ lpParameters As String, ByVal lpDirectory As String, ByVal
nshowcm As Long)

Any suggestions?

(I apologize for my lack of knowledge, but I am a beginner.)

Thanks :)

(ByVal _ should be on the line above.
e.g. .Decl.. "ShellExecuteA" (ByVal _
should be 1 line.
 
J

jande30

Great...that problem is solved. Now, I am having issues entering a path. I
keep getting this error:

Compile Error:
Expected: expression

Here is what I have: strPDFPath = <S:\MANIFEST\Marketing\Graphic
Design\Project Files\Broker_Programs\PDFs>
 
B

Bob Quintal

Great...that problem is solved. Now, I am having issues entering
a path. I keep getting this error:

Compile Error:
Expected: expression

Here is what I have: strPDFPath = <S:\MANIFEST\Marketing\Graphic
Design\Project Files\Broker_Programs\PDFs>
The actual delimiters for the path are doublequotes (")

strPDFPath = "S:\MANIFEST\Marketing\Graphic Design\Project Files
\Broker_Programs\PDFs"

all on 1 line.
Bob Quintal said:
(ByVal _ should be on the line above.
e.g. .Decl.. "ShellExecuteA" (ByVal _
should be 1 line.
 
K

Ken Sheridan

The first problem was due to the line being split over two lines by your
newsgroup reader. This is something you need to watch out for when code is
posted here.

As regards the second problem the use of angle brackets in code samples is
to indicate where some sort of expression needs to be entered at that place
in the paradigm. As Bob says, use quotes to delimit a literal string
expression. It rather looks as though your path does not include the file
name however, so that, including the .pdf extension, should be added to the
string.

Hard coding a path does make maintenance difficult, however, should the
location of the files be changed for instance. Better would be to store the
path to the folder in one field in the underlying table, and the name of the
pdf file in another. That way its simply a question of updating the data in
the table if any changes are necessary. In the code behind the button on
your form you can then assign the path to the variable with:

strPDFPath = Me.FolderPath & "\" Me.FileName

This assumes the FolderPath field does not include a final backslash
character and the FuleName field includes the .pdf extension.

Ken Sheridan
Stafford, England
 
J

jande30

I entered what you wrote below, and now I am getting the following message
when I click the button:

The expression On Click you entered as the even proprety setting produced
the following error: Ambiguous name detected:Command55_Click.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function , even, or macro.

Now what did I do wrong?
 
K

Ken Sheridan

It sounds like you might have entered the code directly in the button's
properties sheet rather than in its event procedure? If so, delete the code,
click on the build button (the one with 3 dots) to the right of the On Click
event property in the properties sheet, select Code Builder and when the VBA
window opens at the event property enter the code between the two lines
already in place.

The properties sheet for the button should show [Event Procedure] as the On
Click event property.

Ken Sheridan
Stafford, England

jande30 said:
I entered what you wrote below, and now I am getting the following message
when I click the button:

The expression On Click you entered as the even proprety setting produced
the following error: Ambiguous name detected:Command55_Click.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function , even, or macro.

Now what did I do wrong?
 
J

jande30

Okay...I entered it into the event procedure. Now I am getting this error
and the word ME (second one) is highlighted:

Compile Error:
Expected: end of statement

Ken Sheridan said:
It sounds like you might have entered the code directly in the button's
properties sheet rather than in its event procedure? If so, delete the code,
click on the build button (the one with 3 dots) to the right of the On Click
event property in the properties sheet, select Code Builder and when the VBA
window opens at the event property enter the code between the two lines
already in place.

The properties sheet for the button should show [Event Procedure] as the On
Click event property.

Ken Sheridan
Stafford, England

jande30 said:
I entered what you wrote below, and now I am getting the following message
when I click the button:

The expression On Click you entered as the even proprety setting produced
the following error: Ambiguous name detected:Command55_Click.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluating the function , even, or macro.

Now what did I do wrong?


Ken Sheridan said:
The first problem was due to the line being split over two lines by your
newsgroup reader. This is something you need to watch out for when code is
posted here.

As regards the second problem the use of angle brackets in code samples is
to indicate where some sort of expression needs to be entered at that place
in the paradigm. As Bob says, use quotes to delimit a literal string
expression. It rather looks as though your path does not include the file
name however, so that, including the .pdf extension, should be added to the
string.

Hard coding a path does make maintenance difficult, however, should the
location of the files be changed for instance. Better would be to store the
path to the folder in one field in the underlying table, and the name of the
pdf file in another. That way its simply a question of updating the data in
the table if any changes are necessary. In the code behind the button on
your form you can then assign the path to the variable with:

strPDFPath = Me.FolderPath & "\" Me.FileName

This assumes the FolderPath field does not include a final backslash
character and the FuleName field includes the .pdf extension.

Ken Sheridan
Stafford, England

:

Great...that problem is solved. Now, I am having issues entering a path. I
keep getting this error:

Compile Error:
Expected: expression

Here is what I have: strPDFPath = <S:\MANIFEST\Marketing\Graphic
Design\Project Files\Broker_Programs\PDFs>

:

in
I keep getting this error message:

Compile error:

Expected: line number or label or statement or end of statement.
It is highlighting the firs ( in the following:

(ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String,
ByVal _ lpParameters As String, ByVal lpDirectory As String, ByVal
nshowcm As Long)

Any suggestions?

(I apologize for my lack of knowledge, but I am a beginner.)

Thanks :)

(ByVal _ should be on the line above.
e.g. .Decl.. "ShellExecuteA" (ByVal _
should be 1 line.
 
Top