Huh ?

G

Guest

what do I need to do to make it so, when I open this form, it automatically
goes to the next entry screen AFTER the last used ? or even to the last
entry would be nice.

Also, is there a place I can go to "learn" how to put my ideas to work in
the Forms / Sub-Forms ?

I have pasted what I believe to be the code for the Form: Time Cards. The
Time Card contains the employee info. The 1st sub-form contains "Payroll"
info and the second Subform contains project (accounting) info.

Option Compare Database
Private Sub cmdLast_click()
On Error GoTo ErrLast
DoCmd.RunCommand acCmdRecordsGoToLast
Exit Sub
ErrLast:
Select Case Err
Case 2046
'Command not available
MsgBox "You are already on the last record.", vbInformation, "Not
Available"
Case Else
MsgBox Err.Number & ":-" & vbCrLf & Err.Description
End Select
End Sub
'****************** Code End ********************

Private Sub Form_Current()
If IsNull(Me![TimeCardID]) Then
DoCmd.GoToControl "EmployeeID"
End If
End Sub

Private Sub Form_Activate()
On Error GoTo Err_Form_Activate
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me![Time Cards Subform].Form![ProjectID].Requery
Me![Time Cards Expense Subform].Form![ProjectID].Requery

Exit_Form_Activate:
Exit Sub

Err_Form_Activate:
MsgBox Err.Description
Resume Exit_Form_Activate
End Sub
Private Sub EmployeeID_NotInList(NewData As String, Response As Integer)
MsgBox "Double-click this field to add an entry to the list."
Response = acDataErrContinue
End Sub
Private Sub EmployeeID_DblClick(Cancel As Integer)
On Error GoTo Err_EmployeeID_DblClick
Dim lngEmployeeID As Long

If IsNull(Me![EmployeeID]) Then
Me![EmployeeID].Text = ""
Else
lngEmployeeID = Me![EmployeeID]
Me![EmployeeID] = Null
End If
DoCmd.OpenForm "Employees", , , , , acDialog, "GotoNew"
Me![EmployeeID].Requery
If lngEmployeeID <> 0 Then Me![EmployeeID] = lngEmployeeID

Exit_EmployeeID_DblClick:
Exit Sub

Err_EmployeeID_DblClick:
MsgBox Err.Description
Resume Exit_EmployeeID_DblClick
End Sub

Private Sub EmployeeID_Click()
Me![Time Cards Subform].Requery
End Sub

Private Sub Time_Cards_Subform_Enter()
If IsNull(Me![EmployeeID]) Then
MsgBox "Enter employee before entering time or expenses."
DoCmd.GoToControl "EmployeeID"
End If
End Sub
Private Sub Time_Cards_Expense_Subform_Enter()
If IsNull(Me![EmployeeID]) Then
MsgBox "Enter employee before entering time or expenses."
DoCmd.GoToControl "EmployeeID"
End If
End Sub
Private Sub PreviewTimeCard_Click()
On Error GoTo PreviewTimeCard_Err
If IsNull(Me![TimeCardID]) Then
MsgBox "Enter time card information before previewing the Time Card
report."
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport "Time Sheet", acPreview, , "[TimeCardID]=" &
[TimeCardID]
End If

PreviewTimeCard_Exit:
Exit Sub

PreviewTimeCard_Err:
MsgBox Err.Description
Resume PreviewTimeCard_Exit
End Sub
 
S

Steve Schapel

John,

Set the Data Entry property of the form to Yes. This is easiest, as
long as you don't want to scroll back and see previously entered
records. Otherwise, put code like this on the Load event of the form...
DoCmd.GoToRecord , , acNewRec

--
Steve Schapel, Microsoft Access MVP

what do I need to do to make it so, when I open this form, it automatically
goes to the next entry screen AFTER the last used ? or even to the last
entry would be nice.

Also, is there a place I can go to "learn" how to put my ideas to work in
the Forms / Sub-Forms ?

I have pasted what I believe to be the code for the Form: Time Cards. The
Time Card contains the employee info. The 1st sub-form contains "Payroll"
info and the second Subform contains project (accounting) info.

Option Compare Database
Private Sub cmdLast_click()
On Error GoTo ErrLast
DoCmd.RunCommand acCmdRecordsGoToLast
Exit Sub
ErrLast:
Select Case Err
Case 2046
'Command not available
MsgBox "You are already on the last record.", vbInformation, "Not
Available"
Case Else
MsgBox Err.Number & ":-" & vbCrLf & Err.Description
End Select
End Sub
'****************** Code End ********************

Private Sub Form_Current()
If IsNull(Me![TimeCardID]) Then
DoCmd.GoToControl "EmployeeID"
End If
End Sub

Private Sub Form_Activate()
On Error GoTo Err_Form_Activate
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me![Time Cards Subform].Form![ProjectID].Requery
Me![Time Cards Expense Subform].Form![ProjectID].Requery

Exit_Form_Activate:
Exit Sub

Err_Form_Activate:
MsgBox Err.Description
Resume Exit_Form_Activate
End Sub
Private Sub EmployeeID_NotInList(NewData As String, Response As Integer)
MsgBox "Double-click this field to add an entry to the list."
Response = acDataErrContinue
End Sub
Private Sub EmployeeID_DblClick(Cancel As Integer)
On Error GoTo Err_EmployeeID_DblClick
Dim lngEmployeeID As Long

If IsNull(Me![EmployeeID]) Then
Me![EmployeeID].Text = ""
Else
lngEmployeeID = Me![EmployeeID]
Me![EmployeeID] = Null
End If
DoCmd.OpenForm "Employees", , , , , acDialog, "GotoNew"
Me![EmployeeID].Requery
If lngEmployeeID <> 0 Then Me![EmployeeID] = lngEmployeeID

Exit_EmployeeID_DblClick:
Exit Sub

Err_EmployeeID_DblClick:
MsgBox Err.Description
Resume Exit_EmployeeID_DblClick
End Sub

Private Sub EmployeeID_Click()
Me![Time Cards Subform].Requery
End Sub

Private Sub Time_Cards_Subform_Enter()
If IsNull(Me![EmployeeID]) Then
MsgBox "Enter employee before entering time or expenses."
DoCmd.GoToControl "EmployeeID"
End If
End Sub
Private Sub Time_Cards_Expense_Subform_Enter()
If IsNull(Me![EmployeeID]) Then
MsgBox "Enter employee before entering time or expenses."
DoCmd.GoToControl "EmployeeID"
End If
End Sub
Private Sub PreviewTimeCard_Click()
On Error GoTo PreviewTimeCard_Err
If IsNull(Me![TimeCardID]) Then
MsgBox "Enter time card information before previewing the Time Card
report."
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport "Time Sheet", acPreview, , "[TimeCardID]=" &
[TimeCardID]
End If

PreviewTimeCard_Exit:
Exit Sub

PreviewTimeCard_Err:
MsgBox Err.Description
Resume PreviewTimeCard_Exit
End Sub
 

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