A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

A Hyperlink button



 
 
Thread Tools Display Modes
  #11  
Old October 5th, 2005, 02:19 AM
SJW123
external usenet poster
 
Posts: n/a
Default

Thanks Bruce for all your helpful advice. Now got it working a treat.
cheers
SJW

"BruceM" wrote:

You should be able to go back and edit the line. You are not limited to
what the automatic feature adds. I am using Access 2000. If you are using
a different version, maybe there is a bug. If so, you could try starting
with just the quotes, then inserting the text and hyphen between them. You
could also use some other punctuation, or none at all, as you prefer. The
point is just to identify the source of the error.
Here's a trick that can come in handy. You can use the code for the ASCII
character in place of the character itself. Your message box code could be:
MsgBox "Error #" & Err.Number & ", " & Err.Description & " " & chr(45) & "
Command93_Click()"
This technique can come in especially handy when you want quote marks within
a text string. Chr(34) is the code for a double quote.


"SJW123" wrote in message
...
Bruce
I tried many times to enter the code exactly as you provided ie.
copy/paste.
But the automatic feature in the code window continually added quote marks
after the hyphen in the MsgeBox error line of code. I do not know how to
'turn off' this automatic feature, so everytime I ran the code there were
syntax errors. However, the final MsgeBox code you provided at the end of
your advice re. wrapping text in the code window works for me. With the
underscore and space, the automatic feature did not add quotation marks
again.
I accept your advice re. naming command buttons. I usually do name tables,
forms, command buttons etc. with more meaningful names, but on this
occasion
I forgot. Many thanks for your help and patience.
SJW

"BruceM" wrote:

If you had entered my code exactly as I provided it, I think it would
have
worked. I wonder why you didn't try that.
Everything between a pair of double quotes is treated as literal text.
You
can put anything you want between quote marks, except that when you want
quote marks to show up in your message box it can get a bit more complex.
When the code window added the quote mark after the hyphen, it added just
the hypen to the message box text. It didn't know what to do with the
rest
of that line of code, since it was not a recognizable command. The
automatic feature can be very handy, but it doesn't always guess
correctly.
..
Another, slightly simpler, way of entering the ProcErr: code would be:

If Err.Number = 2501 Then
GoTo ProcExit
End If
MsgBox "Error #" & Err.Number & ", " & Err.Description & " -
Command93_Click()"
Resume ProcExit

This eliminates the need for Else. If Error 2501 occurs, Exit Sub
occurs;
otherwise, the rest of the code runs. Try putting an apostrophe in front
of
the first three lines of the code above (the line is ignored when you do
this) so that you can see the message box format when Error 2501 occurs.

By the way if you want to wrap the text in a code window, add a space
followed by an underscore, then press the Enter key:

MsgBox "Error #" & Err.Number & ", " & Err.Description & _
" - Command93_Click()"

Note that you can wrap immediately before or immediately after an
ampersand,
not in the middle of a command.

As an aside, you would be doing yourself a favor in the long run if you
used
meaningful names for your controls such as command buttons.

"SJW123" wrote in message
...
Bruce
I have tried to follow your advice but am not successful. I am using
the
following code for Command93 on-click:

Private Sub Command93_Click()
Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink


On Error GoTo ProcErr

Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink

ProcExit:
Exit Sub

ProcErr:
If Err.Number = 2501 Then
GoTo ProcExit
Else
MsgBox "Error #" & Err.Number & ", " & Err.Description & " - "
Command93_Click()"
Resume ProcExit
End If

End Sub

I keep getting a syntax error on the 4th last line of the code
(Command93_Click()")
By the way, my code does differ slightly from yours : " and () were
added
automatically in this line of code.
thanks
SJW

"BruceM" wrote:

You can trap the error. I am calling the command button cmdHyperlink.

Private Sub cmdHyperlink_Click()

On Error GoTo ProcErr

Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink

ProcExit:
Exit Sub

ProcErr:
If Err.Number = 2501 Then
GoTo ProcExit
Else
msgbox "Error #" & Err.Number & ", " & Err.Description &
" - cmdHyperlink_Click"
Resume ProcExit
End If

End Sub

I use some variant of this code for all VBA error handling. If I do
not
need to trap an error I use just the following two lines between
ProcErr
and
End Sub:
msgbox "Error #" & Err.Number & ", " & Err.Description &
" -
cmdHyperlink_Click"
Resume ProcExit

Note that ProcErr: and ProcExit: need to be at the left edge of the
code
window, and need the colons. I like to use just the generic terms
ProcErr:
and ProcExit:, but you could use Err_cmdHyperlink_Click: and
Exit_cmdHyperlink_Click:, or whatever you choose. The message box
words
" -
cmdHyperlink_Click" are to identify the source of the error (very
helpful
during development). You can customize the message box to suit your
preferences.





"SJW123" wrote in message
...
Bruce
Again Thanks.
This works OK for me. the only problem is when you click the command
button,
the insert hyperlink frame appears. If the user chooses to cancels
this
op
without inserting a hyperlink, then a Runtime 2501 error occurs.
The field 'Web' is where the hyperlink for the website is held on
the
form
for users to click on and be directed to the relevant site.
Have taken your advice at latter part of below and works fine.
I certainly don't know of any other way of doing this.
cheers
SJW

"BruceM" wrote:

When dealing with a hyperlink field in a similar situation I
devised
my
own
solution, since I could not find any past posting that related
specifically
to my needs, nor could I elicit an answer to my question in this
forum.
My
"solution" was to make txtHyperlink quite small, make it flat, set
its
back
and fore colors to the same color as the Detail back color
(assuming
txtHyperlink is in the form's Detail section), and tuck it away in
an
inconspicuous corner. If there is a better way I would like to
know
about
it, but this is what I was able to contrive.
I'm a little confused when you refer to the field (Web) being on
the
form.
If it is on the form it needs to be in a control such as a text
box.
In
design view, when you view the "field's" properties, is it
identified
as
a
text box or what? If there is already a text box or something
bound
to
the
Web field you could just apply what I have already written to that
control's
name instead of to txtHyperlink. You do not need a text box named
txtHyperlink. That was intended to be a generic name for whatever
you
already have.
I hope this clarifies it.

"SJW123" wrote in message
...
BruceM thanks
Does this mean I need to have a 3 items on my form to get this to
work -
text box (txtHyperlink) bound to the hyperlink field (Web); the
command
button with the Click event code below; and the original
hyperlink
field
(Web)? This gets confusing. I have tried to hide the
txtHyperlink
text
box,
but the command wont work. The only way is to hide the field
"Web"
and
then
the textbox becomes the "field" on the form. Is this a correct
solution
or
is
there something better? Because I don't want to have 2 fields
(ie.txtHyperlink and Web) displaying the same hyperlink
information
on
the
form.
thanks
SJW

"BruceM" wrote:

I used the following in the command button's Click event:

Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink

txtHyperlink is the text box that is bound to the hyperlink
field.
I
have
not been able to find much discussion on this subject, but from
my
own
experiments it seems that the focus needs to be in a control
bound
to
the
hyperlink field before acCmdInsertHyperlink will work.

"SJW123" wrote in message
...
I have a field on a form which is a hyperlink. Currently, to
insert a
hyperlink the user needs to use the dropdown menu from Insert
or
click
on
the
hyperlink icon on the top toolbar. We constantly have new
users
of
this
database who don't know how to insert a hyperlink, unless they
are
shown.

  #12  
Old October 5th, 2005, 12:09 PM
BruceM
external usenet poster
 
Posts: n/a
Default

You're welcome. Glad we got it worked out. Good luck with the project.

"SJW123" wrote in message
...
Thanks Bruce for all your helpful advice. Now got it working a treat.
cheers
SJW

"BruceM" wrote:

You should be able to go back and edit the line. You are not limited to
what the automatic feature adds. I am using Access 2000. If you are
using
a different version, maybe there is a bug. If so, you could try starting
with just the quotes, then inserting the text and hyphen between them.
You
could also use some other punctuation, or none at all, as you prefer.
The
point is just to identify the source of the error.
Here's a trick that can come in handy. You can use the code for the
ASCII
character in place of the character itself. Your message box code could
be:
MsgBox "Error #" & Err.Number & ", " & Err.Description & " " & chr(45) &
"
Command93_Click()"
This technique can come in especially handy when you want quote marks
within
a text string. Chr(34) is the code for a double quote.


"SJW123" wrote in message
...
Bruce
I tried many times to enter the code exactly as you provided ie.
copy/paste.
But the automatic feature in the code window continually added quote
marks
after the hyphen in the MsgeBox error line of code. I do not know how
to
'turn off' this automatic feature, so everytime I ran the code there
were
syntax errors. However, the final MsgeBox code you provided at the end
of
your advice re. wrapping text in the code window works for me. With the
underscore and space, the automatic feature did not add quotation marks
again.
I accept your advice re. naming command buttons. I usually do name
tables,
forms, command buttons etc. with more meaningful names, but on this
occasion
I forgot. Many thanks for your help and patience.
SJW

"BruceM" wrote:

If you had entered my code exactly as I provided it, I think it would
have
worked. I wonder why you didn't try that.
Everything between a pair of double quotes is treated as literal text.
You
can put anything you want between quote marks, except that when you
want
quote marks to show up in your message box it can get a bit more
complex.
When the code window added the quote mark after the hyphen, it added
just
the hypen to the message box text. It didn't know what to do with the
rest
of that line of code, since it was not a recognizable command. The
automatic feature can be very handy, but it doesn't always guess
correctly.
..
Another, slightly simpler, way of entering the ProcErr: code would be:

If Err.Number = 2501 Then
GoTo ProcExit
End If
MsgBox "Error #" & Err.Number & ", " & Err.Description & " -
Command93_Click()"
Resume ProcExit

This eliminates the need for Else. If Error 2501 occurs, Exit Sub
occurs;
otherwise, the rest of the code runs. Try putting an apostrophe in
front
of
the first three lines of the code above (the line is ignored when you
do
this) so that you can see the message box format when Error 2501
occurs.

By the way if you want to wrap the text in a code window, add a space
followed by an underscore, then press the Enter key:

MsgBox "Error #" & Err.Number & ", " & Err.Description & _
" - Command93_Click()"

Note that you can wrap immediately before or immediately after an
ampersand,
not in the middle of a command.

As an aside, you would be doing yourself a favor in the long run if
you
used
meaningful names for your controls such as command buttons.

"SJW123" wrote in message
...
Bruce
I have tried to follow your advice but am not successful. I am using
the
following code for Command93 on-click:

Private Sub Command93_Click()
Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink


On Error GoTo ProcErr

Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink

ProcExit:
Exit Sub

ProcErr:
If Err.Number = 2501 Then
GoTo ProcExit
Else
MsgBox "Error #" & Err.Number & ", " & Err.Description & " - "
Command93_Click()"
Resume ProcExit
End If

End Sub

I keep getting a syntax error on the 4th last line of the code
(Command93_Click()")
By the way, my code does differ slightly from yours : " and () were
added
automatically in this line of code.
thanks
SJW

"BruceM" wrote:

You can trap the error. I am calling the command button
cmdHyperlink.

Private Sub cmdHyperlink_Click()

On Error GoTo ProcErr

Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink

ProcExit:
Exit Sub

ProcErr:
If Err.Number = 2501 Then
GoTo ProcExit
Else
msgbox "Error #" & Err.Number & ", " & Err.Description
&
" - cmdHyperlink_Click"
Resume ProcExit
End If

End Sub

I use some variant of this code for all VBA error handling. If I
do
not
need to trap an error I use just the following two lines between
ProcErr
and
End Sub:
msgbox "Error #" & Err.Number & ", " & Err.Description
&
" -
cmdHyperlink_Click"
Resume ProcExit

Note that ProcErr: and ProcExit: need to be at the left edge of the
code
window, and need the colons. I like to use just the generic terms
ProcErr:
and ProcExit:, but you could use Err_cmdHyperlink_Click: and
Exit_cmdHyperlink_Click:, or whatever you choose. The message box
words
" -
cmdHyperlink_Click" are to identify the source of the error (very
helpful
during development). You can customize the message box to suit
your
preferences.





"SJW123" wrote in message
...
Bruce
Again Thanks.
This works OK for me. the only problem is when you click the
command
button,
the insert hyperlink frame appears. If the user chooses to
cancels
this
op
without inserting a hyperlink, then a Runtime 2501 error occurs.
The field 'Web' is where the hyperlink for the website is held on
the
form
for users to click on and be directed to the relevant site.
Have taken your advice at latter part of below and works fine.
I certainly don't know of any other way of doing this.
cheers
SJW

"BruceM" wrote:

When dealing with a hyperlink field in a similar situation I
devised
my
own
solution, since I could not find any past posting that related
specifically
to my needs, nor could I elicit an answer to my question in this
forum.
My
"solution" was to make txtHyperlink quite small, make it flat,
set
its
back
and fore colors to the same color as the Detail back color
(assuming
txtHyperlink is in the form's Detail section), and tuck it away
in
an
inconspicuous corner. If there is a better way I would like to
know
about
it, but this is what I was able to contrive.
I'm a little confused when you refer to the field (Web) being on
the
form.
If it is on the form it needs to be in a control such as a text
box.
In
design view, when you view the "field's" properties, is it
identified
as
a
text box or what? If there is already a text box or something
bound
to
the
Web field you could just apply what I have already written to
that
control's
name instead of to txtHyperlink. You do not need a text box
named
txtHyperlink. That was intended to be a generic name for
whatever
you
already have.
I hope this clarifies it.

"SJW123" wrote in message
...
BruceM thanks
Does this mean I need to have a 3 items on my form to get this
to
work -
text box (txtHyperlink) bound to the hyperlink field (Web);
the
command
button with the Click event code below; and the original
hyperlink
field
(Web)? This gets confusing. I have tried to hide the
txtHyperlink
text
box,
but the command wont work. The only way is to hide the field
"Web"
and
then
the textbox becomes the "field" on the form. Is this a correct
solution
or
is
there something better? Because I don't want to have 2 fields
(ie.txtHyperlink and Web) displaying the same hyperlink
information
on
the
form.
thanks
SJW

"BruceM" wrote:

I used the following in the command button's Click event:

Me.txtHyperlink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink

txtHyperlink is the text box that is bound to the hyperlink
field.
I
have
not been able to find much discussion on this subject, but
from
my
own
experiments it seems that the focus needs to be in a control
bound
to
the
hyperlink field before acCmdInsertHyperlink will work.

"SJW123" wrote in message
...
I have a field on a form which is a hyperlink. Currently, to
insert a
hyperlink the user needs to use the dropdown menu from
Insert
or
click
on
the
hyperlink icon on the top toolbar. We constantly have new
users
of
this
database who don't know how to insert a hyperlink, unless
they
are
shown.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I execute command from button or hyperlink? rerhart General Discussion 1 February 18th, 2005 09:41 PM
Add browse button to insert hyperlink function in Outlook. Sarah General Discussion 1 January 14th, 2005 04:01 PM
Hyperlink on command button DP New Users 2 December 12th, 2004 12:44 PM
Using Hyperlinks in Mail Merge IF...THEN...ELSE Statements Mark V Mailmerge 8 November 30th, 2004 01:31 PM
Still having Web Page Pathing Problems / Relative Links show Netwo webmaster Powerpoint 27 July 15th, 2004 11:16 PM


All times are GMT +1. The time now is 01:04 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.