Code won't work

G

Guest

Can anyone tell me what is wrong with this code.

There are 42 boxes on my form with 4 text boxes each. Each box represents a
day of the week. The boxes are named D1-D42, F1-F42, R1-R42, & B1-B42. The
"D" represents the # of the day on the calendar. F, R, & B is info that is
pulled from a query. What I am trying to do is show a cumalitive for each
day, based on the 3 categories.

Dim CurDay, CurDayFlat, CurDayRot, CurDayB
Dim FTally, RTally, BTally As Long
Dim rs As recordset
Dim db As Database

For x = 1 To 42

With rs
Do While Not rs.EOF

CurDay = Me("D" & x)
CurDayFlat = ("F" & x)
CurDayRot = ("R" & x)
CurDayB = ("B" & x)

If ![Date Due] = CurDay And ![PSAbrv] = "F" Then
FTally = ![SP_Est] + FTally
Me(CurDayFlat) = FTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "R" Then
RTally = ![SP_Est] + RTally
Me(CurDayRot) = RTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "B" Then
BTally = ![SP_Est] + BTally
Me(CurDayB) = BTally
End If


rs.MoveNext
Loop

End With

Next x
 
M

Marshall Barton

steve said:
Can anyone tell me what is wrong with this code.

There are 42 boxes on my form with 4 text boxes each. Each box represents a
day of the week. The boxes are named D1-D42, F1-F42, R1-R42, & B1-B42. The
"D" represents the # of the day on the calendar. F, R, & B is info that is
pulled from a query. What I am trying to do is show a cumalitive for each
day, based on the 3 categories.

Dim CurDay, CurDayFlat, CurDayRot, CurDayB
Dim FTally, RTally, BTally As Long
Dim rs As recordset
Dim db As Database

For x = 1 To 42

With rs
Do While Not rs.EOF

CurDay = Me("D" & x)
CurDayFlat = ("F" & x)
CurDayRot = ("R" & x)
CurDayB = ("B" & x)

If ![Date Due] = CurDay And ![PSAbrv] = "F" Then
FTally = ![SP_Est] + FTally
Me(CurDayFlat) = FTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "R" Then
RTally = ![SP_Est] + RTally
Me(CurDayRot) = RTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "B" Then
BTally = ![SP_Est] + BTally
Me(CurDayB) = BTally
End If


rs.MoveNext
Loop

End With

Next x


The code you posted never sets the rs object.

It's also missing the Me in 3 statements.
 
G

Guest

I cut and pasted this code from different places. The rs Object is set. I am
also not sure what lines are missing the Me statement. Can you clarify?

The code here executes, it just dosen't do what I want it to do. All of the
fields for each of the days come up as 0. My guess is that I am not
referencing the field names correctly. With the value I assign to "CurDayFlat
= ("F" & x)", I am trying to reference the name of the text box on my form.
Is this the correct way to do this.

Marshall Barton said:
steve said:
Can anyone tell me what is wrong with this code.

There are 42 boxes on my form with 4 text boxes each. Each box represents a
day of the week. The boxes are named D1-D42, F1-F42, R1-R42, & B1-B42. The
"D" represents the # of the day on the calendar. F, R, & B is info that is
pulled from a query. What I am trying to do is show a cumalitive for each
day, based on the 3 categories.

Dim CurDay, CurDayFlat, CurDayRot, CurDayB
Dim FTally, RTally, BTally As Long
Dim rs As recordset
Dim db As Database

For x = 1 To 42

With rs
Do While Not rs.EOF

CurDay = Me("D" & x)
CurDayFlat = ("F" & x)
CurDayRot = ("R" & x)
CurDayB = ("B" & x)

If ![Date Due] = CurDay And ![PSAbrv] = "F" Then
FTally = ![SP_Est] + FTally
Me(CurDayFlat) = FTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "R" Then
RTally = ![SP_Est] + RTally
Me(CurDayRot) = RTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "B" Then
BTally = ![SP_Est] + BTally
Me(CurDayB) = BTally
End If


rs.MoveNext
Loop

End With

Next x


The code you posted never sets the rs object.

It's also missing the Me in 3 statements.
 
M

Marshall Barton

To reference controls on the form, you do need to use me (as
you did in one statement).

CurDayFlat = Me("F" & x)
CurDayRot = Me("R" & x)
CurDayB = Me("B" & x)

You will also need a MoveFirst after the For statement.

We really don't care where you got the code, but, if you
want us to debug it, it is very important that you Copy
Paste the code with the problem so we don't waste time
debugging copy/paste mistakes or typos.
--
Marsh
MVP [MS Access]



steve said:
I cut and pasted this code from different places. The rs Object is set. I am
also not sure what lines are missing the Me statement. Can you clarify?

The code here executes, it just dosen't do what I want it to do. All of the
fields for each of the days come up as 0. My guess is that I am not
referencing the field names correctly. With the value I assign to "CurDayFlat
= ("F" & x)", I am trying to reference the name of the text box on my form.
Is this the correct way to do this.

steve said:
Can anyone tell me what is wrong with this code.

There are 42 boxes on my form with 4 text boxes each. Each box represents a
day of the week. The boxes are named D1-D42, F1-F42, R1-R42, & B1-B42. The
"D" represents the # of the day on the calendar. F, R, & B is info that is
pulled from a query. What I am trying to do is show a cumalitive for each
day, based on the 3 categories.

Dim CurDay, CurDayFlat, CurDayRot, CurDayB
Dim FTally, RTally, BTally As Long
Dim rs As recordset
Dim db As Database

For x = 1 To 42

With rs
Do While Not rs.EOF

CurDay = Me("D" & x)
CurDayFlat = ("F" & x)
CurDayRot = ("R" & x)
CurDayB = ("B" & x)

If ![Date Due] = CurDay And ![PSAbrv] = "F" Then
FTally = ![SP_Est] + FTally
Me(CurDayFlat) = FTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "R" Then
RTally = ![SP_Est] + RTally
Me(CurDayRot) = RTally
End If

If ![Date Due] = CurDay And ![PSAbrv] = "B" Then
BTally = ![SP_Est] + BTally
Me(CurDayB) = BTally
End If


rs.MoveNext
Loop

End With

Next x
Marshall Barton said:
The code you posted never sets the rs object.

It's also missing the Me in 3 statements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top