Code question (1 Viewer)

Peter Paul

Registered User.
Local time
Today, 05:35
Joined
Jan 1, 2000
Messages
82
Greetings,
I am having a difficult time with something which should, I think, be pretty easy. I have a subform with three fields. Focus should only go to the third field if the data in the second field meets the criteria, else it should tab to a new record on the first field.

I have been trying this code, and variations on it, but the tab continues to move to the last field regardless. I do have the tab property set to NO for the third field.

If Me.secondfield <= 15 Then Me.Lastfield.setfocus
IF Me.secondfield > 15 then Me.Firstfield.setfocus

I don't think I should even need the second line of code, but for some reason it is not working properly.

Thank you for any assistance,
Peter Paul

[This message has been edited by Peter Paul (edited 04-03-2001).]
 

Abby N

Registered User.
Local time
Today, 05:35
Joined
Aug 22, 2000
Messages
123
Hello Peter. Here's some code that should do the trick. Set the third fields 'Tab Stop' property back to 'Yes' and use this in it's 'OnEnter' property.

If Me.secondfield > 15 Then
DoCmd.GoToRecord acDataForm, "Form Name", acNewRec
Me.Firstfield.SetFocus
End If

That should do the trick. Alternatively, just as a personal preference, you could use the following code in the forms 'OnCurrent' event and the second control's 'AfterUpdate' event.

If Me.secondfield <= 15 then
Me.Lastfield.Enabled = False
else
Me.Lastfield.Enabled = True
End If

That way the third field is grayed out and can't be entered until the value in the second field is greater than 15. One final note, be sure the forms 'Cycle' property is set to 'All Records'. Good luck.

~Abby

[This message has been edited by Abby N (edited 04-04-2001).]
 

Peter Paul

Registered User.
Local time
Today, 05:35
Joined
Jan 1, 2000
Messages
82
Thanks, but it is still not working. I am thinking I did not provide enough information.

The field is on a subform, and is set to Continuous Form. I may have done something wrong in naming the form.

Me.secondfield > 15 Then
DoCmd.GoToRecord acDataForm, Forms!Formname!subform, acNewRec
Me.Firstfield.SetFocus
End If

Is my naming convention wrong for the form designation?

Thanks again
Peter
 

Abby N

Registered User.
Local time
Today, 05:35
Joined
Aug 22, 2000
Messages
123
Ah. I hadn't realized you were working in a subform. Luckily, if you omit the object type and name then the GoToRecord method will assume you want to manipulate the current object, which of course we do. So this code should do it.

If Me.secondfield > 15 Then
DoCmd.GoToRecord , , acNewRec
Me.Firstfield.SetFocus
End If

~Abby
 

Users who are viewing this thread

Top Bottom