SetFocus on another form

V

Vincdc

Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
O

Ofer

First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus
 
V

Vincdc

I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


Ofer said:
First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



Vincdc said:
Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
O

Ofer

What is the code that you used?
Did you get an error?




Vincdc said:
I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


Ofer said:
First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



Vincdc said:
Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
V

Vincdc

My code is as following. It seems that VB does not recognize "
stDocName.City.SetFocus".

Private Sub Add_New_City_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "City"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
stDocName.City.SetFocus

End Sub



Ofer said:
What is the code that you used?
Did you get an error?




Vincdc said:
I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


Ofer said:
First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
O

Ofer

Try this

Forms!City!City.SetFocus



Vincdc said:
My code is as following. It seems that VB does not recognize "
stDocName.City.SetFocus".

Private Sub Add_New_City_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "City"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
stDocName.City.SetFocus

End Sub



Ofer said:
What is the code that you used?
Did you get an error?




Vincdc said:
I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


:

First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
V

Vincdc

Thanks! This one works.
One more question: if I click this button, can I set the value for a field
in form B too, e.g. set focus on City and set its Group as "LA"?


Ofer said:
Try this

Forms!City!City.SetFocus



Vincdc said:
My code is as following. It seems that VB does not recognize "
stDocName.City.SetFocus".

Private Sub Add_New_City_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "City"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
stDocName.City.SetFocus

End Sub



Ofer said:
What is the code that you used?
Did you get an error?




:

I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


:

First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
O

Ofer

I'm not sure if that what you mean, but you can assign a value to field in a
different form

Forms!City!Group = "LA"

Vincdc said:
Thanks! This one works.
One more question: if I click this button, can I set the value for a field
in form B too, e.g. set focus on City and set its Group as "LA"?


Ofer said:
Try this

Forms!City!City.SetFocus



Vincdc said:
My code is as following. It seems that VB does not recognize "
stDocName.City.SetFocus".

Private Sub Add_New_City_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "City"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
stDocName.City.SetFocus

End Sub



:

What is the code that you used?
Did you get an error?




:

I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


:

First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
V

Vincdc

Yes, it works. Thanks a lot! :)

Ofer said:
I'm not sure if that what you mean, but you can assign a value to field in a
different form

Forms!City!Group = "LA"

Vincdc said:
Thanks! This one works.
One more question: if I click this button, can I set the value for a field
in form B too, e.g. set focus on City and set its Group as "LA"?


Ofer said:
Try this

Forms!City!City.SetFocus



:

My code is as following. It seems that VB does not recognize "
stDocName.City.SetFocus".

Private Sub Add_New_City_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "City"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
stDocName.City.SetFocus

End Sub



:

What is the code that you used?
Did you get an error?




:

I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


:

First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
O

Ofer

Glad I could help
--


Vincdc said:
Yes, it works. Thanks a lot! :)

Ofer said:
I'm not sure if that what you mean, but you can assign a value to field in a
different form

Forms!City!Group = "LA"

Vincdc said:
Thanks! This one works.
One more question: if I click this button, can I set the value for a field
in form B too, e.g. set focus on City and set its Group as "LA"?


:

Try this

Forms!City!City.SetFocus



:

My code is as following. It seems that VB does not recognize "
stDocName.City.SetFocus".

Private Sub Add_New_City_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "City"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
stDocName.City.SetFocus

End Sub



:

What is the code that you used?
Did you get an error?




:

I tried the both. Change the tab order works well, but the code on form load
event does not work. I would like to know how the code would work if you have
the idea.
Thank you very much!


:

First you can use the Field TabOrder to set this field to be the first one,
so you won't need to set the focus, it will automatically get the focus been
the first one in the order

Or, on the load event of the form, write the code
Me.[Enter here the Field Name in the form].SetFocus

--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



:

Hello:
I have a button in form A which will open form B to add new records. I also
want to set focus on a field in form B when it it opened. My code is as
following

DoCmd.RunCommand acCmdRecordsGoToNew
Myfield.SetFocus

However, when I click the button, the cursor will not move to the Myfield
and I always got error message saying "Object Required"
Any suggestions?
Thanks in advance!
 
Top