Adding records

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
 
D

David

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
 

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