Noreene Patrick
Registered User.
- Local time
- Today, 11:49
- Joined
- Jul 18, 2002
- Messages
- 223
I have attached following code to a command button to enter data in a form for my calendar. My only problem is the last line:
When I click the command button, code runs fine until empname.setfocus. Then the line is highlighted in yellow and wont take focus of the command button. What am I doing wrong?
I only want focus to go on empname when next record appears. Otherwise, the focus is still on command button on the new record.
Can anyone help?
Private Sub Command10_Click()
'capture the values of the date & number of days
Dim numOfDays As Long
numOfDays = Me.Duration
Dim StartDate As Date
StartDate = Me.StartDate
'create records in the same table for each day
' incrementing the date for each record
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
Dim sqlStr As String
Dim i As Integer
For i = 1 To numOfDays
sqlStr = "INSERT INTO tbltimeoffrequests(EmpName,Shift,StartDate,Duration) VALUES('" & Me![EmpName] & "', '" & Me.Shift & "',"
sqlStr = sqlStr & "#" & StartDate + i & "#," & Me.Duration & ")"
conn.Execute sqlStr
Next
DoCmd.GoToRecord , , acNewRec
EmpName.SetFocus
When I click the command button, code runs fine until empname.setfocus. Then the line is highlighted in yellow and wont take focus of the command button. What am I doing wrong?
I only want focus to go on empname when next record appears. Otherwise, the focus is still on command button on the new record.
Can anyone help?
Private Sub Command10_Click()
'capture the values of the date & number of days
Dim numOfDays As Long
numOfDays = Me.Duration
Dim StartDate As Date
StartDate = Me.StartDate
'create records in the same table for each day
' incrementing the date for each record
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
Dim sqlStr As String
Dim i As Integer
For i = 1 To numOfDays
sqlStr = "INSERT INTO tbltimeoffrequests(EmpName,Shift,StartDate,Duration) VALUES('" & Me![EmpName] & "', '" & Me.Shift & "',"
sqlStr = sqlStr & "#" & StartDate + i & "#," & Me.Duration & ")"
conn.Execute sqlStr
Next
DoCmd.GoToRecord , , acNewRec
EmpName.SetFocus