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

O

Ofer

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
 
D

DaveInSAT

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.
 
O

Ofer

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.
 
D

DaveInSAT

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.
 
D

DaveInSAT

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.
 
O

Ofer

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.
 
D

DaveInSAT

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.
 
O

Ofer

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.
 
O

Ofer

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.
 
Top