adding multiple records
Hi,
What I am trying to do is to add multiple records at one time.
I have a form with a startdate, an enddate and an artikelnumber. What I would like to have is that when I click on an action button (that has already been made) the records are entered automatically.
The start and enddate will always be a monday. I need the first added record to be the startdate and than every monday that follows (so startdate +7) untill the last record that is added equals the enddate.
The code that is currently linked to the action button is:
Private Sub BijkomendeInvoer_Click()
Dim sArt, sSQL As String
Dim rs As ADODB.Recordset
Dim i, iStart, iEnd As Date
'check for filled combo boxes
'check startdate
If IsNull(Me.Begindatum) Or Me.Begindatum = "" Then
MsgBox "Gelieve een begindatum in te voeren." & vbCrLf & "Veuillez entrer une date de départ.", vbExclamation
Exit Sub
Else
iStart = Me.Begindatum
End If
'check enddate
If IsNull(Me.Einddatum) Or Me.Einddatum = "" Then
MsgBox "Gelieve een einddatum in te voeren." & vbCrLf & "Veuillez enter une date de fin.", vbExclamation
Exit Sub
Else
iEnd = Me.Einddatum
End If
'check to see if start date is less than end date
If iStart > iEnd Then
MsgBox "De einddatum bevindt zich voor de begindatum." & vbCrLf & "La date de départ se situe après la date de fin.", vbExclamation
Exit Sub
End If
'check artikel
If IsNull(Me.Artikelnummer) Or Me.Artikelnummer = "" Then
MsgBox "Gelieve een artikelnummer in te voeren." & vbCrLf & "Veuillez entrer un numéro d'article.", vbExclamation
Exit Sub
Else
sArt = Me.Artikelnummer
End If
'define recordset to ADD new records with this data
sSQL = "select * from tblTestBuyBA01"
'open recordset and connection
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject, adOpenDynamic, adLockOptimistic
'add all records here
Do Until iStart = iEnd
rs.AddNew
rs("Datum") = iStart
rs("Artikelnummer") = sArt
rs.Update
iStart = iStart + 7
Loop
rs.Close
MsgBox "De Test Buy werd ingevoerd." & vbCrLf & "Le Test Buy a été inséré.", vbInformation
End Sub
Does anyone know what should be changed to this code for it to work?
The fields stardate, enddate and artikelnumber are set up on an unbound form in access 2002. The table where the records needs to be added is tblTestBuyBA01 like you can see in the code. The fields names that are required to fill in are "datum" for date and "artikelnummer" for the artikelnumber...
The line in the code that creates the error is:
rs.Open sSQL, CurrentProject, adOpenDynamic, adLockOptimistic
|