Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Not Keeping Focus

Status
Not open for further replies.

Lightning

Technical User
Jun 24, 2000
1,140
AU
On a main form I have a combo box which lists Account numbers.&nbsp;&nbsp;When a user types in a number which is not in the list, I use the Openform command to open a secondary form to enter the new data in the Account Number field, and then move to the next field (on the secondary form) for the user to start inputting further information.&nbsp;&nbsp;My code is as follows:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim ans As Integer<br><font color=green>'Clear the combo box</font><br>&nbsp;&nbsp;&nbsp;&nbsp;Me![AccountNumber] = Null<br>&nbsp;&nbsp;&nbsp;&nbsp;Response = 0<br><font color=green>'Display a message box for the user</font><br>&nbsp;&nbsp;&nbsp;&nbsp;ans = MsgBox(&quot;Account Number does not exist.&nbsp;&nbsp;&quot; & _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Do you want to add it to the list?&quot;, vbYesNo + vbExclamation, &quot;Add a new Account?&quot;)<br><font color=green>'If user clicks &quot;Yes&quot; then open the Tenancy form in Add mode</font><br>&nbsp;&nbsp;&nbsp;&nbsp;<b>If ans = vbYes Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.OpenForm &quot;frmTenancy&quot;, acNormal, , , acFormAddNew</b> <font color=red>Problem Here I Think</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Forms!frmTenancy![AccountNumber] = NewData<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.GoToControl &quot;[Tenant]&quot;<br><br>The problem is that the [Tenant] field will not hold the focus - the focus jumps to another textbox on the form.<br>This would be very confusing for my users (and is annoying me no end!).<br>The problem only occurs when I open the form in Add mode.&nbsp;&nbsp;If I open it in Edit mode, the focus stays where it should. This is what makes me think the problem is with the OpenForm AddNew line in my code.<br><br>Has anyone else had a problem like this, and can anyone suggest a solution?<br><br>Thanks in advance<br>Lightning<br>
 
Lightning,<br><br>A few suggestions worth giving a try.<br>1.&nbsp;&nbsp;Do not go to any control via code on the secondary form, but make the control you want the focus to be in the lowest item in the tab order.<br>2.&nbsp;&nbsp;If you do not trust #1, in the secondary form's on open event, set the focus on the desired control.<br>3.&nbsp;&nbsp;If the above two are not appropriate for your needs, instead of docmd.gotocontrol, use forms!frmTenancy!Tenant.setfocus <p>-Chopper<br><a href=mailto: > </a><br><a href= > </a><br>
 
Thanks, Chopper - #1 seems to be the solution.

Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top