Can I index by anyone of a FORM's text box ? (VBA)

  • Thread starter Martin \(Martin Lee\)
  • Start date
M

Martin \(Martin Lee\)

I have a FORM which contains a lot of textboxes (each textbox belong to a
field).

I want to make a button on this FORM : firstly I would place the mouse to
anyone of the textbox, and then I click this button --- what I want is, when
I click this button, the FORM will index by THIS textbox's field.

How should the VBA of this BUTTTON be?

Thank you.



Martin Lee
 
D

Douglas J Steele

What do you mean by indexing a textbox field?

You can create a common function for your form that uses Screen
ActiveControl to know which control is currently active. With the form open
in Design mode, select all of the text boxes of interest to you ("lasso"
them, or hold down the Shift key while you click on them). With all of them
selected, you can simply put =MyFunction in the box beside the MouseDown
event, and that function will be called when the mouse is clicked in any of
the text boxes.
 
M

Martin \(Martin Lee\)

No no no, Mr. Steele, it's not what I want :)

This problem is about a BUTTON's VBA sentence.

Background: I open the FORM according to some filter criteria, so, the FROM
could show several records one by one(by click the right-arrow little button
on the left-down side)--- this is the background introduction to my
question. OK, my explanation of my question is like below:

I want to establish a button on this FORM. First, the VBA of the button
should know which TEXTBOX my mouse is staying in, and then index the records
by the content of this textbox.

How to write this VBA? Thanks!


Martin Lee
 
D

Douglas J Steele

Recognize that when you click on a button, the mouse is not in a textbox:
it's on the button.

Fortunately, Access keeps track of the previous control: rather than
Screen.ActiveControl, refer to Screen.PreviousControl in the code for your
button.

However, since you still haven't explained what you mean by "index the
records by the content of this textbox", that's as much as I can provide.
 
M

Martin \(Martin Lee\)

Thanks, yet, this method seems a bit difficult for me to understand .

"index the records" means, for example,(there are a few records one by one
which could be explored through the FORM) if the FORM's textbox1's content
is a TEXT, the records will be index(arrange) into "A to Z" or "Z to A"; If
the textbox2's content is a DATE, the records will be index(arrange) from
1900-01-01 to 2006-05-08 (for example).

Sorry for my poor English express. :)


Martin Lee
 
D

Douglas J Steele

It sounds, then, like you want something like the following in your button's
Click event:

If TypeOf Screen.PreviousControl Is TextBox Then
Me.OrderBy = Screen.PreviousControl.ControlSource
Me.OrderByOn = True
End If
 
M

Martin \(Martin Lee\)

I think it will work. I will try.

Thank you Mr. Stelle.

Martin Lee
 
A

Albert D.Kallal

The term "index" has a particular meaning in ms-access, an thus your use in
this case is confusing.

It sounds to me that you want to be able to sort by any field in the
form....

this feature is built in-to ms-access...

Simply right click on the field...and choose the sort ascending
option....that is it.....

you don't need any code at all here...this feature is part of ms-access...

Just right click on the text box....you will see the list of options.....
 
M

Martin \(Martin Lee\)

Yeah!Yeah! You know what I was thinking. exactlyl SORT! Sorry for my poor
English, because I am not using the English edition of Access.

But, the problem is: I want to make a "sort" BUTTON in the FORM, so that the
user can operate easily.

Martin Lee
 

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