get control name

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi

I need to populate an unbound textbox with the names of the controls I click
on. Should I set up in every control's onclick event and write:

me.txtcontrolname = me.control.name

or is there an easier way? I have quite a lot of controls in the form.

Thanks in advance

Richard

--
 
Create a function in the form's class module - (replace Text10 with the name
of the your unbound control).

private function DisplayCtlName()
Me.Text10 = Me.ActiveControl.Name
End function

Then select all of the controls that have a click event and while all are
selected put the following into the Click Event property:

=DisplayCtlName()

Any particular reason why you are doing this? Just curious . . .
 
Hi Sandra

Thanks for your help.

The reason is that the recordset is growing bigger and very slow to open(50
secs to open). I am planning to open only one most recent record on the
form(view only). The users will use two unbound text boxes, one for criteria
and one for field, which is the bound to a query for the form's record
source.

Am I doing the right thing here? Or is there any other way?

Thanks again
Richard

--


Sandra Daigle said:
Create a function in the form's class module - (replace Text10 with the name
of the your unbound control).

private function DisplayCtlName()
Me.Text10 = Me.ActiveControl.Name
End function

Then select all of the controls that have a click event and while all are
selected put the following into the Click Event property:

=DisplayCtlName()

Any particular reason why you are doing this? Just curious . . .

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi

I need to populate an unbound textbox with the names of the controls
I click on. Should I set up in every control's onclick event and
write:

me.txtcontrolname = me.control.name

or is there an easier way? I have quite a lot of controls in the form.

Thanks in advance

Richard
 
Hi Richard,

I'm still not sure I understand how it will help you to have one control
display the name of the one that has the focus.

Regarding speeding up your form you are probably on the right track to use a
search form that limits the number of records returned to your data form. It
is always best to restrict the number of records returned to the smallest
number possible. This solves and prevents many problems.

For general tips on improving performance see
http://www.granite.ab.ca/access/performancefaq.htm

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi Sandra

Thanks for your help.

The reason is that the recordset is growing bigger and very slow to
open(50 secs to open). I am planning to open only one most recent
record on the form(view only). The users will use two unbound text
boxes, one for criteria and one for field, which is the bound to a
query for the form's record source.

Am I doing the right thing here? Or is there any other way?

Thanks again
Richard


Sandra Daigle said:
Create a function in the form's class module - (replace Text10 with
the name of the your unbound control).

private function DisplayCtlName()
Me.Text10 = Me.ActiveControl.Name
End function

Then select all of the controls that have a click event and while
all are selected put the following into the Click Event property:

=DisplayCtlName()

Any particular reason why you are doing this? Just curious . . .

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi

I need to populate an unbound textbox with the names of the controls
I click on. Should I set up in every control's onclick event and
write:

me.txtcontrolname = me.control.name

or is there an easier way? I have quite a lot of controls in the
form.

Thanks in advance

Richard
 
Hi Sandra

I have tried it and it seems that I need the control's recordsource and not
the name. Then on click on a find button, I will manipulate the form's
record source with this code:

source = "SELECT .............
"WHERE " & Me.txtfield & " Like """ & "*" & Me.txtlookup & "*" &
""""

Me.RecordSource = source

Do querying data by controlling the record source easier to control or by
creating recordsets? Anyway I tried creating a recordset and only one record
appeared on the form. How do we populate the form with all records?

Thanks again

Richard


--


Sandra Daigle said:
Hi Richard,

I'm still not sure I understand how it will help you to have one control
display the name of the one that has the focus.

Regarding speeding up your form you are probably on the right track to use a
search form that limits the number of records returned to your data form. It
is always best to restrict the number of records returned to the smallest
number possible. This solves and prevents many problems.

For general tips on improving performance see
http://www.granite.ab.ca/access/performancefaq.htm

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi Sandra

Thanks for your help.

The reason is that the recordset is growing bigger and very slow to
open(50 secs to open). I am planning to open only one most recent
record on the form(view only). The users will use two unbound text
boxes, one for criteria and one for field, which is the bound to a
query for the form's record source.

Am I doing the right thing here? Or is there any other way?

Thanks again
Richard


Sandra Daigle said:
Create a function in the form's class module - (replace Text10 with
the name of the your unbound control).

private function DisplayCtlName()
Me.Text10 = Me.ActiveControl.Name
End function

Then select all of the controls that have a click event and while
all are selected put the following into the Click Event property:

=DisplayCtlName()

Any particular reason why you are doing this? Just curious . . .

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.


Richard wrote:
Hi

I need to populate an unbound textbox with the names of the controls
I click on. Should I set up in every control's onclick event and
write:

me.txtcontrolname = me.control.name

or is there an easier way? I have quite a lot of controls in the
form.

Thanks in advance

Richard
 
Hi Richard,

Just change the function to get the controlSource of the ActiveControl:

private function DisplayCtlName()
Me.txtfield = Me.ActiveControl.ControlSource
End function

Regarding the way you query the data, the best method depends on your
situation. I frequently do it in a manner similar to the method you are
using.

When you say you tried creating a recordset, what exactly did you do? How
did you bind the recordset to the form (or did you bind it?). Post your code
and I'll be glad to take a look.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi Sandra

I have tried it and it seems that I need the control's recordsource
and not the name. Then on click on a find button, I will manipulate
the form's record source with this code:

source = "SELECT .............
"WHERE " & Me.txtfield & " Like """ & "*" & Me.txtlookup &
"*" & """"

Me.RecordSource = source

Do querying data by controlling the record source easier to control
or by creating recordsets? Anyway I tried creating a recordset and
only one record appeared on the form. How do we populate the form
with all records?

Thanks again

Richard



Sandra Daigle said:
Hi Richard,

I'm still not sure I understand how it will help you to have one
control display the name of the one that has the focus.

Regarding speeding up your form you are probably on the right track
to use a search form that limits the number of records returned to
your data form. It is always best to restrict the number of records
returned to the smallest number possible. This solves and prevents
many problems.

For general tips on improving performance see
http://www.granite.ab.ca/access/performancefaq.htm

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi Sandra

Thanks for your help.

The reason is that the recordset is growing bigger and very slow to
open(50 secs to open). I am planning to open only one most recent
record on the form(view only). The users will use two unbound text
boxes, one for criteria and one for field, which is the bound to a
query for the form's record source.

Am I doing the right thing here? Or is there any other way?

Thanks again
Richard


Create a function in the form's class module - (replace Text10 with
the name of the your unbound control).

private function DisplayCtlName()
Me.Text10 = Me.ActiveControl.Name
End function

Then select all of the controls that have a click event and while
all are selected put the following into the Click Event property:

=DisplayCtlName()

Any particular reason why you are doing this? Just curious . . .

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.


Richard wrote:
Hi

I need to populate an unbound textbox with the names of the
controls I click on. Should I set up in every control's onclick
event and write:

me.txtcontrolname = me.control.name

or is there an easier way? I have quite a lot of controls in the
form.

Thanks in advance

Richard
 
Hi Sandra

I tried the query on the main db which is linked to the backend and it still
took around 30 seconds to open one record. What I am doing now is open the
form based on a saved query. I takes only about less than 10 secs to open.

If I use a recordset and bind to a form, will it be faster or more
efficient? I don't know how to bind the recordset to the form. Here what I
tried:

Private Sub Form_Open(Cancel As Integer)
Dim DB As dao.database
Dim rst As dao.Recordset

Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT A.firstname FROM wbdata As A ")

With rst
Do Until .EOF
Me.txtpartname = !FIRSTNAME
.MoveNext

Loop
.Close

End With
Set rst = Nothing
End Sub

The form ends up with only one record.

Thanks for helping me out with this. Appreciate it.

Richard
--


Sandra Daigle said:
Hi Richard,

Just change the function to get the controlSource of the ActiveControl:

private function DisplayCtlName()
Me.txtfield = Me.ActiveControl.ControlSource
End function

Regarding the way you query the data, the best method depends on your
situation. I frequently do it in a manner similar to the method you are
using.

When you say you tried creating a recordset, what exactly did you do? How
did you bind the recordset to the form (or did you bind it?). Post your code
and I'll be glad to take a look.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Hi Sandra

I have tried it and it seems that I need the control's recordsource
and not the name. Then on click on a find button, I will manipulate
the form's record source with this code:

source = "SELECT .............
"WHERE " & Me.txtfield & " Like """ & "*" & Me.txtlookup &
"*" & """"

Me.RecordSource = source

Do querying data by controlling the record source easier to control
or by creating recordsets? Anyway I tried creating a recordset and
only one record appeared on the form. How do we populate the form
with all records?

Thanks again

Richard



Sandra Daigle said:
Hi Richard,

I'm still not sure I understand how it will help you to have one
control display the name of the one that has the focus.

Regarding speeding up your form you are probably on the right track
to use a search form that limits the number of records returned to
your data form. It is always best to restrict the number of records
returned to the smallest number possible. This solves and prevents
many problems.

For general tips on improving performance see
http://www.granite.ab.ca/access/performancefaq.htm

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.


Richard wrote:
Hi Sandra

Thanks for your help.

The reason is that the recordset is growing bigger and very slow to
open(50 secs to open). I am planning to open only one most recent
record on the form(view only). The users will use two unbound text
boxes, one for criteria and one for field, which is the bound to a
query for the form's record source.

Am I doing the right thing here? Or is there any other way?

Thanks again
Richard


Create a function in the form's class module - (replace Text10 with
the name of the your unbound control).

private function DisplayCtlName()
Me.Text10 = Me.ActiveControl.Name
End function

Then select all of the controls that have a click event and while
all are selected put the following into the Click Event property:

=DisplayCtlName()

Any particular reason why you are doing this? Just curious . . .

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.


Richard wrote:
Hi

I need to populate an unbound textbox with the names of the
controls I click on. Should I set up in every control's onclick
event and write:

me.txtcontrolname = me.control.name

or is there an easier way? I have quite a lot of controls in the
form.

Thanks in advance

Richard
 
Back
Top