ThingKing88
Technical User
I have created a calendar form where information is coming from different areas as well as being interactive. The last part of the calendar is not working out so well. One of the criteria is actual hours. I have a query that gives me actual hours. I created a form from the query, but the only value that shows up on the calendar is the first record in the form/query. The following is what I have in the Control Source box for the text box on the form:
=IIf([txtDateA26]=Forms!frmEHvsAH![Service Date] And [fldClientID]=Forms!frmEHvsAH![Client ID],Forms!frmEHvsAH![Actual Hours],"0")
There are 42 text boxes like this on the form. I would like to have all the records to appear.
I have tried vb code for this, but it didn't work. see below:
Public Sub PutInActualHours()
Dim strSQL As String
Dim f As Form
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim counter As Integer
Dim fld As Field
Dim i As Integer, j As Integer
For j = 0 To 41
Set f = Forms!frmCalendar
strSQL = "select [qryActualHours].ActualHours from [qryActualHours] where (([qryActualHours].ServiceDate = " _
& f("txtDateA" & j) & " and [qryActualHours].ClientID = " & f!fldClientID & ")) order by ServiceDate;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
If rs.RecordCount > 0 Then
rs.MoveFirst
Do While Not rs.EOF
For i = 0 To 41
If rs!ServiceDate = f("txtDateA" & i) Then
rs.FindFirst "ServiceDate=#" & f("txtDateA" & i) & "#"
If Not rs.NoMatch Then
f("txtAHA" & i) = rs!actualhours
'Else
' f("txtAHA" & i) = 0
End If
End If
Next i
rs.MoveNext
Loop
End If
Next j
End Sub
I have tried other code, but I get an error saying that I can't assign a value to the object f("txtAHA" i)
can anyone help?
thank you
=IIf([txtDateA26]=Forms!frmEHvsAH![Service Date] And [fldClientID]=Forms!frmEHvsAH![Client ID],Forms!frmEHvsAH![Actual Hours],"0")
There are 42 text boxes like this on the form. I would like to have all the records to appear.
I have tried vb code for this, but it didn't work. see below:
Public Sub PutInActualHours()
Dim strSQL As String
Dim f As Form
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim counter As Integer
Dim fld As Field
Dim i As Integer, j As Integer
For j = 0 To 41
Set f = Forms!frmCalendar
strSQL = "select [qryActualHours].ActualHours from [qryActualHours] where (([qryActualHours].ServiceDate = " _
& f("txtDateA" & j) & " and [qryActualHours].ClientID = " & f!fldClientID & ")) order by ServiceDate;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
If rs.RecordCount > 0 Then
rs.MoveFirst
Do While Not rs.EOF
For i = 0 To 41
If rs!ServiceDate = f("txtDateA" & i) Then
rs.FindFirst "ServiceDate=#" & f("txtDateA" & i) & "#"
If Not rs.NoMatch Then
f("txtAHA" & i) = rs!actualhours
'Else
' f("txtAHA" & i) = 0
End If
End If
Next i
rs.MoveNext
Loop
End If
Next j
End Sub
I have tried other code, but I get an error saying that I can't assign a value to the object f("txtAHA" i)
can anyone help?
thank you