How do I refer to the active record in a form within a query?

  • Thread starter Thread starter Guest
  • Start date Start date
Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio
 
The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

Ofer said:
Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

DaveInSAT said:
Thanks for any help.
 
Yes
follow this steps
1. Create a function in a module called GetActiveFieldName
Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyFormName].ActiveControl ' change the
form name
GetActiveFieldName = ctlCurrentControl.Name End Functio
End Function

2. create a query, and call the function and see that it returns the name of
the active field.

Select *, GetActiveFieldName() as activefield Form MyTable

Now the question is, what do you want to do with it, if you want the value
of the active field, then try this
forms![MyFormName](GetActiveFieldName())

Select *, forms![MyFormName](GetActiveFieldName())
as activefield Form MyTable

DaveInSAT said:
The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

Ofer said:
Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

DaveInSAT said:
Thanks for any help.
 
I see said the blind man. Your help is greatly appreciated. Thank you and
have great day.

Ofer said:
Yes
follow this steps
1. Create a function in a module called GetActiveFieldName
Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyFormName].ActiveControl ' change the
form name
GetActiveFieldName = ctlCurrentControl.Name End Functio
End Function

2. create a query, and call the function and see that it returns the name of
the active field.

Select *, GetActiveFieldName() as activefield Form MyTable

Now the question is, what do you want to do with it, if you want the value
of the active field, then try this
forms![MyFormName](GetActiveFieldName())

Select *, forms![MyFormName](GetActiveFieldName())
as activefield Form MyTable

DaveInSAT said:
The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

Ofer said:
Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

:

Thanks for any help.
 
Ofer,

within the query get the error undefined function 'forms![frm XXX] in
expression.

the form is active -

what am i missing????

Many Thanks,
David

Ofer said:
Yes
follow this steps
1. Create a function in a module called GetActiveFieldName
Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyFormName].ActiveControl ' change the
form name
GetActiveFieldName = ctlCurrentControl.Name End Functio
End Function

2. create a query, and call the function and see that it returns the name of
the active field.

Select *, GetActiveFieldName() as activefield Form MyTable

Now the question is, what do you want to do with it, if you want the value
of the active field, then try this
forms![MyFormName](GetActiveFieldName())

Select *, forms![MyFormName](GetActiveFieldName())
as activefield Form MyTable

DaveInSAT said:
The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

Ofer said:
Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

:

Thanks for any help.
 
Please post the SQL, Form Name, And the function you created, which I assume
you created in a module and not under the form

DaveInSAT said:
Ofer,

within the query get the error undefined function 'forms![frm XXX] in
expression.

the form is active -

what am i missing????

Many Thanks,
David

Ofer said:
Yes
follow this steps
1. Create a function in a module called GetActiveFieldName
Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyFormName].ActiveControl ' change the
form name
GetActiveFieldName = ctlCurrentControl.Name End Functio
End Function

2. create a query, and call the function and see that it returns the name of
the active field.

Select *, GetActiveFieldName() as activefield Form MyTable

Now the question is, what do you want to do with it, if you want the value
of the active field, then try this
forms![MyFormName](GetActiveFieldName())

Select *, forms![MyFormName](GetActiveFieldName())
as activefield Form MyTable

DaveInSAT said:
The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

:

Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

:

Thanks for any help.
 
within a module as you suspected:

Public Function Dave()
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Forms![frm Partner Deal information].ActiveControl
Dave = ctlCurrentControl.Name
End Function

within the query as a criteria :
forms![frm Partner Deal information](Dave())

form is open and the field is highlighted where i have the criteria above.

thanks


Ofer said:
Please post the SQL, Form Name, And the function you created, which I assume
you created in a module and not under the form

DaveInSAT said:
Ofer,

within the query get the error undefined function 'forms![frm XXX] in
expression.

the form is active -

what am i missing????

Many Thanks,
David

Ofer said:
Yes
follow this steps
1. Create a function in a module called GetActiveFieldName
Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyFormName].ActiveControl ' change the
form name
GetActiveFieldName = ctlCurrentControl.Name End Functio
End Function

2. create a query, and call the function and see that it returns the name of
the active field.

Select *, GetActiveFieldName() as activefield Form MyTable

Now the question is, what do you want to do with it, if you want the value
of the active field, then try this
forms![MyFormName](GetActiveFieldName())

Select *, forms![MyFormName](GetActiveFieldName())
as activefield Form MyTable

:

The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

:

Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

:

Thanks for any help.
 
Within the query you should write only the function name
within the query as a criteria :
Dave()



DaveInSAT said:
within a module as you suspected:

Public Function Dave()
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Forms![frm Partner Deal information].ActiveControl
Dave = ctlCurrentControl.Name
End Function

within the query as a criteria :
forms![frm Partner Deal information](Dave())

form is open and the field is highlighted where i have the criteria above.

thanks


Ofer said:
Please post the SQL, Form Name, And the function you created, which I assume
you created in a module and not under the form

DaveInSAT said:
Ofer,

within the query get the error undefined function 'forms![frm XXX] in
expression.

the form is active -

what am i missing????

Many Thanks,
David

:

Yes
follow this steps
1. Create a function in a module called GetActiveFieldName
Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyFormName].ActiveControl ' change the
form name
GetActiveFieldName = ctlCurrentControl.Name End Functio
End Function

2. create a query, and call the function and see that it returns the name of
the active field.

Select *, GetActiveFieldName() as activefield Form MyTable

Now the question is, what do you want to do with it, if you want the value
of the active field, then try this
forms![MyFormName](GetActiveFieldName())

Select *, forms![MyFormName](GetActiveFieldName())
as activefield Form MyTable

:

The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

:

Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

:

Thanks for any help.
 
And the function should be

Public Function Dave()
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Forms![frm Partner Deal information].ActiveControl
Dave = forms![frm Partner Deal information](ctlCurrentControl.Name)
End Function

Try first running the function without the query and see if it returns a
value, use the immidiate widows for that.
within the query as a criteria :




DaveInSAT said:
within a module as you suspected:

Public Function Dave()
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Forms![frm Partner Deal information].ActiveControl
Dave = ctlCurrentControl.Name
End Function

within the query as a criteria :
forms![frm Partner Deal information](Dave())

form is open and the field is highlighted where i have the criteria above.

thanks


Ofer said:
Please post the SQL, Form Name, And the function you created, which I assume
you created in a module and not under the form

DaveInSAT said:
Ofer,

within the query get the error undefined function 'forms![frm XXX] in
expression.

the form is active -

what am i missing????

Many Thanks,
David

:

Yes
follow this steps
1. Create a function in a module called GetActiveFieldName
Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyFormName].ActiveControl ' change the
form name
GetActiveFieldName = ctlCurrentControl.Name End Functio
End Function

2. create a query, and call the function and see that it returns the name of
the active field.

Select *, GetActiveFieldName() as activefield Form MyTable

Now the question is, what do you want to do with it, if you want the value
of the active field, then try this
forms![MyFormName](GetActiveFieldName())

Select *, forms![MyFormName](GetActiveFieldName())
as activefield Form MyTable

:

The Active Control is only applicable to in macros I thought, I'm trying to
refer to it within a query. Is this possible?

Thanks again.
David

:

Try and read the help about the active control

You can use the ActiveControl property together with the Screen object to
identify or refer to the control that has the focus. Read-only Control object.

Try and create a function that return the active control, and then you can
call this function from a query

Function GetActiveFieldName()
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Forms![MyForm].ActiveControl
GetActiveFieldName = ctlCurrentControl.Name End Functio

:

Thanks for any help.
 

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

Back
Top