Code not working?

  • Thread starter Thread starter Henrootje
  • Start date Start date
H

Henrootje

I have a table called 'Urenregistratie' which (among other fields) the
fields 'Datum' (Datefield) and 'Engineer' (text)
I have a query called 'qryVulnaam' which contains the field 'Vulnaam'
(NameToAdd).

In short: For every name in qryVulnaam I want the dates #1/1/2007# to
#12/31/2007# added.

like
John Malkovich #1/1/2007#
John Malkovich #1/2/2007#
....
John Malkovich #31/12/2007#

Al Gore #1/1/2007#
Al Gore #1/2/2007#
....
Al Gore #31/12/2007#

and so on.... I thought this code would do the trick but simply nothing
gets added to the table even though the msgbox shows the right data
everytime.........

-----------------------------------code-----------------------------------

Dim DateToAdd As Date
Dim NameToAdd As String

Dim db As DAO.Database
Dim rsEngineer As DAO.Recordset
Dim rsUrenTabel As DAO.Recordset


Set db = CurrentDb
Set rsEngineer = db.OpenRecordset("qryVulnaam", dbOpenDynaset)
Set rsUrenTabel = db.OpenRecordset("Urenregistratie",
dbOpenDynaset)


With rsEngineer
.MoveFirst
While Not .EOF
NameToAdd = !VulNaam
With rsUrenTabel
For DateToAdd = Me.Datum + 1 To Me.Datum +
3

.AddNew
!Datum = DateToAdd
!Engineer = NameToAdd
MsgBox NameToAdd & Chr(10) & "
!Datum =" & dtWhen & Chr(10) & " !Engineer =" & TeVullenNaam
.Update
Next
End With

.MoveNext
Wend
MsgBox "Ready"

End With
 
putting this code in a function (not under a button) and adding 'Option
Explicit' solved my problem, code turned out to be ok
 
Back
Top