SetFocus on another form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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
 
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!
 
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!
 
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!
 
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!
 
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!
 
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!
 
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!
 
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!
 

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

Similar Threads


Back
Top