I am trying to create some code that, when command button clicked, records created in an existing table. I have two text boxes, startdate and enddate. In the table there are two fields, date and roomno. I want the code to enter a record for every date between the two text boxes, and for each room. However, for some reason, it tries to enter a null value in the roomNo field.
Here is the code:
Private Sub CmdDates_Click()
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim temp1 As Integer
Dim count As Integer
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("roomdate", dbOpenDynaset)
With rs
Do While StartDate < EndDate
count = 1
Do While count < 10
.AddNew
Date = StartDate
roomno = count
.Update
count = count + 1
Loop
StartDate = StartDate + 1
Loop
End With
End Sub
The roomNo and date are the composite key for the table RoomDate. Its probably something really obvious, but Ive been staring at it for too long!!
Please Help!
Ben.
Here is the code:
Private Sub CmdDates_Click()
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim temp1 As Integer
Dim count As Integer
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("roomdate", dbOpenDynaset)
With rs
Do While StartDate < EndDate
count = 1
Do While count < 10
.AddNew
Date = StartDate
roomno = count
.Update
count = count + 1
Loop
StartDate = StartDate + 1
Loop
End With
End Sub
The roomNo and date are the composite key for the table RoomDate. Its probably something really obvious, but Ive been staring at it for too long!!
Please Help!
Ben.
Last edited: