Can't find Sendkeys

J

Jill

I can't find the Sendkeys macro in Access 2007. Microsoft says the database
has to be trusted or it won't show. My database IS trusted, but still no
Sendkeys. At least as far as I know, it is trusted. I added it's path and
don't have to enable the content when opened.

Any ideas where Sendkeys could be?

Thanks, J~
 
C

CompGeek78

I can't find the Sendkeys macro in Access 2007. Microsoft says the database
has to be trusted or it won't show. My database IS trusted, but still no
Sendkeys. At least as far as I know, it is trusted. I added it's path and
don't have to enable the content when opened.

Any ideas where Sendkeys could be?

Thanks, J~

In almost all cases there are better ways to accomplish things that
using SendKeys. Most experienced Access programmers will tell you to
avoid SendKeys. It's even gone so far that it is mentioned in the
Access Web 10 Commandments, "9. Thou shalt not use "SendKeys", "Smart
Codes" or "GoTo" (unless the GoTo be part of an OnError process) for
these will lead you from the path of righteousness."

One of the biggest issues with SendKeys is that you don't have 100%
control over which window receives the SendKeys commands. If the user
clicks some other window while your code is executing, the keystrokes
could be sent to some other window, possibly doing damage to something
unintentionally.

If you take a moment to explain what you are trying to accomplish,
someone might be able to offer a better alternative than using
SendKeys.

Keven Denen
 
J

Jill

Keven,

Since I am the only person working in this database, the open windows
shouldn't be a problem. Although - there might be a better way to do what I
need to do.

I am simply adding html tags in a field. I use the sendkeys macros to make
<b> and </b> tags, for example. (Bold opening and closing html tags - in
case the actual tags won't show here)

It's still a bit of a pain to have to keep going back and forth to the macro
toolbar. I wonder if there is a way to highlight the needed text and use a
shortcut key to add a <b> (opening b) at the beginning of the text, and a
</b> (closing b) at the end of it, at the same time. Sort of like you would
in a word processor, but instead of just making the text bold, it would add
the tags on either end.

Jeff,

Thanks again!

Jill~




I can't find the Sendkeys macro in Access 2007. Microsoft says the
database
has to be trusted or it won't show. My database IS trusted, but still no
Sendkeys. At least as far as I know, it is trusted. I added it's path and
don't have to enable the content when opened.

Any ideas where Sendkeys could be?

Thanks, J~

In almost all cases there are better ways to accomplish things that
using SendKeys. Most experienced Access programmers will tell you to
avoid SendKeys. It's even gone so far that it is mentioned in the
Access Web 10 Commandments, "9. Thou shalt not use "SendKeys", "Smart
Codes" or "GoTo" (unless the GoTo be part of an OnError process) for
these will lead you from the path of righteousness."

One of the biggest issues with SendKeys is that you don't have 100%
control over which window receives the SendKeys commands. If the user
clicks some other window while your code is executing, the keystrokes
could be sent to some other window, possibly doing damage to something
unintentionally.

If you take a moment to explain what you are trying to accomplish,
someone might be able to offer a better alternative than using
SendKeys.

Keven Denen
 
S

Steve Schapel

Jill,

I think if you click the 'Show All Actions' button on the macro design
ribbon, you will be able to see the SendKeys action.

On the other hand, you would probably be able to achieve your purpose by
running an Update Query. It is not clear to me exactly where you are
inserting these tags, so can't advise explicitly. But check out the Replace
function.
 
J

Jill

Thanks Steve, but I guess I didn't make it very clear.

It's like this - Let's say I have the following text in a memo field:

**I think if you click the Show All Actions button on the macro design
ribbon, you will be able to see the SendKeys action.**


and I want to put <b> and </b> tags around "you will be able to see", so
that it would look like this:

**I think if you click the Show All Actions button on the macro design
ribbon, <b>you will be able to see</b> the SendKeys action.**


Using Sendkeys, I have a macro for the <b> and another for the </b>. But, I
would like to be able to just highlight (select) the words "you will be able
to see" and then use some keyboard shortcut (like control-B) to insert both
tags at once, one on each end of the selected text.

So I don't have to put the cursor at the start of the text, go to the <b>
button, move the cursor to the end of the text, go to the </b> button. Can
you say spoiled? Lazy?

Anyway, is that possible?

Thanks, Jill~
 
L

Larry Linson

Jill said:
Thanks Steve, but I guess I didn't make it very clear.

It's like this - Let's say I have the following text in a memo field:

**I think if you click the Show All Actions button on the macro design
ribbon, you will be able to see the SendKeys action.**


and I want to put <b> and </b> tags around "you will be able to see", so
that it would look like this:

**I think if you click the Show All Actions button on the macro design
ribbon, <b>you will be able to see</b> the SendKeys action.**


Using Sendkeys, I have a macro for the <b> and another for the </b>. But,
I would like to be able to just highlight (select) the words "you will be
able to see" and then use some keyboard shortcut (like control-B) to
insert both tags at once, one on each end of the selected text.

So I don't have to put the cursor at the start of the text, go to the <b>
button, move the cursor to the end of the text, go to the </b> button. Can
you say spoiled? Lazy?

Anyway, is that possible?

Yes, it is _possible_ to insert markup in that manner. I wrote a small
application to apply a limited set of HTML markup to notes for a particular
website, more as an experiment than for "practical use". I did not use
SendKeys, and found that Access and VBA were not a "good fit" for creating a
text editor. Once I figured out workable approaches, the application still
seemed clumsy, and the code was definitely not trivial, nor even simple.

So, while it may be possible, I would not advise doing so. If you come up
with a simple, straightforward approach using SendKeys or other methods, I'd
like to hear more.

Larry Linson
Microsoft Office Access MVP
 
S

Steve Schapel

Jill,

I recommended that you check out the Replace function. Did you? It seems
ideally suited to the scenario you have now described.

Update YourMemoField to:
Replace([YourMemoField],"you will be able to see","<b>you will be able to
see</b>")
 
J

Jill

Well, I don't think that would be much easier than using the sendkeys
macros, because the text that needs the bold tags would change for every
record.

But maybe this would work? :

Replace([MyMemoField],[LastName] & "," & [FirstName],"<b>[LastName & ", " &
[FirstName]</b>")

Is that a workable expression?


Steve Schapel said:
Jill,

I recommended that you check out the Replace function. Did you? It seems
ideally suited to the scenario you have now described.

Update YourMemoField to:
Replace([YourMemoField],"you will be able to see","<b>you will be able to
see</b>")

--
Steve Schapel, Microsoft Access MVP


Jill said:
Thanks Steve, but I guess I didn't make it very clear.

It's like this - Let's say I have the following text in a memo field:

**I think if you click the Show All Actions button on the macro design
ribbon, you will be able to see the SendKeys action.**


and I want to put <b> and </b> tags around "you will be able to see", so
that it would look like this:

**I think if you click the Show All Actions button on the macro design
ribbon, <b>you will be able to see</b> the SendKeys action.**


Using Sendkeys, I have a macro for the <b> and another for the </b>. But,
I would like to be able to just highlight (select) the words "you will be
able to see" and then use some keyboard shortcut (like control-B) to
insert both tags at once, one on each end of the selected text.

So I don't have to put the cursor at the start of the text, go to the <b>
button, move the cursor to the end of the text, go to the </b> button.
Can you say spoiled? Lazy?

Anyway, is that possible?

Thanks, Jill~
 
S

Steve Schapel

Jill,

Well, I was just responding to your example.

Yes, you can certainly do something like you are suggesting. Except the
syntax is not quite right... try like this:

Replace([MyMemoField],[LastName] & "," & [FirstName],"<b>" & [LastName & ",
" & [FirstName] & "</b>")

This would assume that there is potentially text within the field that is
identical with the text returned by the expression:
[LastName] & "," & [FirstName]
 
J

John Spencer

Copy the following UNTESTED function to a VBA module and use an AUTOKEYS
macro to call the code or use menu items to call the code. Save the
module with a name other than fsetHTMLCode.

You can query ACCESS HELP on AUTOKEYS to find out how to build an
autokeys macro.

Public Function fSetHTMLCode(Optional strStartHTML As String = "<b>" _
, Optional strEndHTML As String = "<\b>")
'Use an AUTOKEYS macro or a menu item to call this code
'If you want bold HTML tags then call it without arguments
'If you want some other tag like italics then call it with
' fSetHTMLCode("<i>","</i")
'If you just wanted a set of parens added you could use
'"(" and ")" as the arguments

Dim ctl As Control
Dim LStart As Long
Dim LEnd As Long
Dim strReplace As String
Dim strContent As String

On Error GoTo Proc_Error

Set ctl = Screen.ActiveControl

If ctl.ControlType = acTextBox Then
If Len(ctl.Text & "") > 0 Then
LStart = ctl.SelStart + 1
LEnd = ctl.SelLength
If LEnd > 0 Then 'Something is selected
strContent = ctl.Text
strReplace = Mid(strContent, LStart, LEnd)

ctl.Text = Left(strContent, LStart - 1) & strStartHTML _
& strReplace & strEndHTML _
& Mid(strContent, LStart + LEnd)
End If 'lend >0
End If 'Length check
End If 'Correct control type

On Error GoTo Proc_Error

Proc_Exit:
Exit Function

Proc_Error:
'Do NOTHING if an error occurs or
'if you want an error message uncomment the following
'line by removing the ' at the beginning of the next line
'MsgBox Err.Number & ": " & Err.Description, , "fSetHTMLCode"
End Function



'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

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