Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Display data in form based on recordset

$
0
0
Hi,
I am trying to enter new/or review data in a table using a form (FWQRainfall) to specify the start (StartDate) and end (EndDate) dates. If records between these start and end dates do not exist they need to be created in the table. I found some code which gets me part of the way there - it generates new records if required, but i cannot get the records to udate and display on the form based on the specified dates. I am not sure what is wrong with syntax on the highlighted line of code below, if i block this line out the new records are created in the table (t_WQ_Rainfall) would appreciate any help. Thanks

Private Sub cmdGenRecords_Click()
Dim rs As DAO.Recordset
Dim sSQL As String
Dim sSDate As String
Dim sEDate As String

sSDate = "#" & Format(Me.txtStartDate, "yyyy/mm/dd") & "#"
sEDate = "#" & Format(Me.txtEndDate, "yyyy/mm/dd") & "#"
sSQL = "SELECT * FROM t_WQ_Rainfall WHERE DataDate Between " & sSDate _
& " AND " & sEDate

Set rs = CurrentDb.OpenRecordset(sSQL)

If rs.RecordCount < (Me.txtEndDate - Me.txtStartDate) Then
AddRecords sSDate, sEDate

End If

[COLOR="rgb(255, 0, 255)"] Me.fWQRainfall.Recordset = sSQL[/COLOR]


End Sub



Sub AddRecords(sSDate, sEDate)

sSQL = "INSERT INTO t_WQ_Rainfall (DataDate) " _
& "SELECT AddDate FROM " _
& "(SELECT " & sSDate _
& " + [counter.ID] AS AddDate " _
& "FROM [Counter] " _
& "WHERE " & sSDate _
& "+ [counter.ID] Between " & sSDate _
& " And " & sEDate & ") a " _
& "WHERE AddDate NOT In (SELECT DataDate FROM t_WQ_Rainfall)"

CurrentDb.Execute sSQL, dbFailOnError
End Sub

Viewing all articles
Browse latest Browse all 13329

Trending Articles