Adding records

  • Thread starter Thread starter Jonathan Stratford
  • Start date Start date
J

Jonathan Stratford

Hi,

I'm trying to make a button which, when clicked, will add
all the dates of all weekends in the current year to a
table. This is the code i use, but it says i'm trying to
add too many records after it tries to add the second.
Can anyone give me any help on this?

Thanks in advance,

Jonathan Stratford

Dim con As Connection
Dim strSQL As String
Dim rs As Recordset
DoCmd.Close acForm, Me.Name, acSaveYes
Set con = Application.CurrentProject.Connection



Set rs = CreateObject("ADODB.Recordset")
rs.Open "TSpecialDays", con, adOpenDynamic,
adLockBatchOptimistic

For newDate = CDate("1/1/" & Year(Now())) To CDate
("31/12/" & Year(Now()))
If WeekdayName(Weekday(newDate)) = "Sunday" Or WeekdayName
(Weekday(newDate)) = "Saturday" Then
MsgBox newDate & " " & WeekdayName(Weekday(newDate))
rs.AddNew "Special Day Date", CStr(newDate)
rs.Update
End If
Next
rs.Close
Set rs = Nothing
Set con = Nothing
 
Use adLockOptimistic instead of adLockBatchOptimisti

----- Jonathan Stratford wrote: ----

Hi

I'm trying to make a button which, when clicked, will add
all the dates of all weekends in the current year to a
table. This is the code i use, but it says i'm trying to
add too many records after it tries to add the second.
Can anyone give me any help on this

Thanks in advance

Jonathan Stratfor

Dim con As Connectio
Dim strSQL As Strin
Dim rs As Recordse
DoCmd.Close acForm, Me.Name, acSaveYe
Set con = Application.CurrentProject.Connectio



Set rs = CreateObject("ADODB.Recordset"
rs.Open "TSpecialDays", con, adOpenDynamic,
adLockBatchOptimisti

For newDate = CDate("1/1/" & Year(Now())) To CDat
("31/12/" & Year(Now())
If WeekdayName(Weekday(newDate)) = "Sunday" Or WeekdayNam
(Weekday(newDate)) = "Saturday" The
MsgBox newDate & " " & WeekdayName(Weekday(newDate)
rs.AddNew "Special Day Date", CStr(newDate
rs.Updat
End I
Nex
rs.Clos
Set rs = Nothin
Set con = Nothin
 
Back
Top