Question on this code

G

Gator

Following is code that I click a button and the program makes sure that a
textbox (PayDate) is not null and if it is, then the textbox remains focused,
and if it is not null, then it proceeds to the tabbed control to a certain
page and to the subform. The subform's initial record is defaulted with the
field 'Fund Number' value of '0' and field 'Amount' with '$0.00'. When I
enter a date in the textbox the reaction is to start a new record rather than
the intended action of going to the subform. I think since there is a
default record of value 0 in the subform the program treats this as a not
null record and proceeds to the new record. How is the best way to fix this
that if the subform doesn't have another record other than '0' then it
highlights the first record, first field for entry. Also, will this work if
I hit enter after entering the date in the textbox? Should I enter this code
in a Private Sub PayDate_Enter ()?

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

If IsNull(Me.PayDate) Then
Me!PayDate.SetFocus
Else
Me.TabCtl27.Pages(0).SetFocus
Me.PayablesDetailssubform1.SetFocus
If IsNull(Me.PayablesDetailssubform1) Then
Me.TabCtl27.Pages(0).SetFocus
Me.PayablesDetailssubform1.SetFocus
Else
Me!PayDate.SetFocus
DoCmd.GoToRecord , , acNewRec
PayDate.SetFocus
End If
End If


Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click

End Sub
 
G

Gator

I enter a date into the textbox. and then either click the button or hit
enter. If there is a valid date, then the focus moves to the first record of
the datasheet on the subform on a tabbed control's page. If there is not a
valid date, then the focus stays in the textbox waiting for a valid date.
What is currently happening is that there will be a valid date and when I hit
enter or click the command button, a new record is generated on the Main Form
rather than focusing to the datasheet subform in the tabbed control on the
previous record.
 

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

Top