code problem with form

R

roger

Somehow when the user clicks on the finish button it takes
him back to the first page but the old record is still
there instead of all the fields being blank and the
capacity for the new user to enter the new record. I am
pasting the code here.


Private Sub Form_Open(Cancel As Integer)


On Error GoTo Err_Form_Open

DoCmd.Maximize
DoCmd.GoToRecord , , acNext


[FirstName].SetFocus

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Error$
Resume Exit_Form_Open

End Sub
................

Private Sub cmdFinish_Click()
'check to see that the visitor has put in atleast a value
other than 0 in any of the boxes.
'if not then prompt him to do that definetely.
If (txtAgeUnder18.Value = 0) And (txtAge18to24 = 0) And
(txtAge25to34 = 0) And (txtAge35to44 = 0) And
(txtAge45to54 = 0) And (txtAge55to64 = 0) And
(txtAge65to74 = 0) And (txtAgeOver74 = 0) Then
MsgBox "PLease enter a value other than 0 in atleast one
of the fields"
[txtAgeUnder18].SetFocus
Exit Sub
End If
DoCmd.OpenForm "frmsplash"
'test...GoToPage 1

Dim tbc As Control, pge As Page
' Return reference to tab control.
Set tbc = Me!TabCtl0
' Return reference to currently selected page.
Set pge = tbc.Pages(0)
pge.SetFocus
Form_Activate
End Sub
.............
Private Sub Form_Activate()

On Error GoTo Err_Form_Activate
Dim pge As Page
DoCmd.Maximize
DoCmd.GoToRecord , , acNext
'Me![First Name].SetFocus
'pge.SetFocus
Exit_Form_Activate:
Exit Sub
Err_Form_Activate:
MsgBox Error$
Resume Exit_Form_Activate
............
 
A

Allen Browne

Form_Open is too early to move record like that. Try Form_Load.

If you want to move to a new record:

Private Sub Form_Load
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
End Sub

Alternatively, you could open the form in DataEntry mode:
DoCmd.OpenForm "MyForm", datamode:=acFormAdd
 

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