Where do subroutines go?


K

Ken Curtis

I am currently building a data base, and it is going very well for exactly
two reasons: First, I don't give up, and, second, you folks are GREAT !!!
Really. All of you have been staggeringly helpful, deeply knowledgble, openly
willing to help, super creative ... and fast!

That said (and it really should be said more often), I have one of those
questions that must leave you people looking at your screens and wondering
how I manage to walk and breathe at the same time. And rightly so. But ...
I really do need this question answered.

When you create something like this (below) in response to a problem I have
posed I don't know where to put it. Do I copy and paste it into the
"Properties" area (i.e. onclick, beforeupdate, etc), is it a "macro" (which
I am only now beginning to understand is not a nerdy abreviation for Kraft
Dinner), or ... or ... or. I know that it will work because you folks
thought it through, but I suspect that it would work far better if I actually
added it to something, somewhere. Is there a general rule for this (except
for 'lock the guy up')?

Thanks ! Here's the example:

Private Sub YourTextBoxName_Click()
Me.YourTextBoxName.SelStart = 0
End Sub

Regards
 
Ad

Advertisements

K

Keith Wilby

Ken Curtis said:
I am currently building a data base, and it is going very well for exactly
two reasons: First, I don't give up, and, second, you folks are GREAT !!!
Really. All of you have been staggeringly helpful, deeply knowledgble,
openly
willing to help, super creative ... and fast!

That said (and it really should be said more often), I have one of those
questions that must leave you people looking at your screens and wondering
how I manage to walk and breathe at the same time. And rightly so. But
...
I really do need this question answered.

When you create something like this (below) in response to a problem I
have
posed I don't know where to put it. Do I copy and paste it into the
"Properties" area (i.e. onclick, beforeupdate, etc), is it a "macro"
(which
I am only now beginning to understand is not a nerdy abreviation for Kraft
Dinner), or ... or ... or. I know that it will work because you folks
thought it through, but I suspect that it would work far better if I
actually
added it to something, somewhere. Is there a general rule for this
(except
for 'lock the guy up')?

Thanks ! Here's the example:

Private Sub YourTextBoxName_Click()
Me.YourTextBoxName.SelStart = 0
End Sub

Hi Ken.

That snippet of code should go in the "click" event of the text box
"YourTextBoxName". It looks like someone has offered you this code as a
solution because "YourTextBoxName" is almost certainly not the name that you
have given to your text box.

So, click on your text box in form design view and click on the "properties"
menu button to show the properties dialog box. On the "event" tab, find the
"on click" event and click slightly to the right of the white box. This
will reveal a small button containing 3 dots and also a drop-down menu.
Select "[Event Procedure]" from the drop-down box and then click on the
button with 3 dots.

This will open a code module where you need to paste the line

Me.YourTextBoxName.SelStart = 0

where "YourTextBoxName" is the actual name of the text box. You can get
that name (if you don't know it) from the first line of code "Private Sub
<name>_Click()"

If all 3 lines of code already exist in the form's code module, then all you
need to do is select "[Event Procedure]" from the click event drop-down box.

Hope that helps.

Keith.
www.keithwilby.com
 
Ad

Advertisements

F

fredg

I am currently building a data base, and it is going very well for exactly
two reasons: First, I don't give up, and, second, you folks are GREAT !!!
Really. All of you have been staggeringly helpful, deeply knowledgble, openly
willing to help, super creative ... and fast!

That said (and it really should be said more often), I have one of those
questions that must leave you people looking at your screens and wondering
how I manage to walk and breathe at the same time. And rightly so. But ...
I really do need this question answered.

When you create something like this (below) in response to a problem I have
posed I don't know where to put it. Do I copy and paste it into the
"Properties" area (i.e. onclick, beforeupdate, etc), is it a "macro" (which
I am only now beginning to understand is not a nerdy abreviation for Kraft
Dinner), or ... or ... or. I know that it will work because you folks
thought it through, but I suspect that it would work far better if I actually
added it to something, somewhere. Is there a general rule for this (except
for 'lock the guy up')?

Thanks ! Here's the example:

Private Sub YourTextBoxName_Click()
Me.YourTextBoxName.SelStart = 0
End Sub

Regards

1) Most likely, this code should be in the [YourTextBoxName] Enter
event, not it's Click event, but my example will show the Click event
anyway.

2) Here's how you 'write' code.

Open the form in design view.
Right-click on the [YourTextBoxName] control.
Select Properties.
Click on the Event tab.
On the Click event line, write:

[Event Procedure]

Then click on the little button with the 3 dots that appears on that
line. When the code window opens, the cursor will be flashing between
2 already written lines of code ..

Private Sub YourTextBoxName_Click()

End Sub

Between those 2 lines write:

Me.YourTextBoxName.SelStart = 0

Exit the code window and save the changes when you close the form.
 

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