When it comes to access, I'm pretty good using the built in features
and can come up with some pretty complex functions to get what I need.
But we have this database I'm doing for work that is trying to pull in
too many things. The database is a construction job estimating
program. First you setup a project, then you add items that will be
needed for the job and you create a cost estimate. You then send this
list out to construction companies who turn in their bids, which are
added in to the program. The last step is to create a bid tabulation
report, that is a cross tab of the original estimate along w/ the bids
from the various construction companies.
This was more complex than I could handle, so we hired someone to do
it. 4 attempts later and a few thousand dollars and this report still
does not function properly. Right now I'm attempting to learn VBA
and fix this damned thing myself.
But, I'm having trouble making sense fo this code he's put in, to
figure out why 1 out of 5 times the "Total" variable puts in a "$1"
instead of calculating the total by multiplying the unit * quantity.
Any help would be greatly appreciated.
Below is the code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' Place values in text boxes and hide unused text boxes.
Dim Contractor As String
Dim TempContractor
'Dim ItemCombo As Long
Dim ItemCombo As String
Dim i As Integer
Dim intX As Integer
Dim TempWMTotal As Single
' Verify that not at end of recordset.
If Not rstReport.EOF Then
' If FormatCount is 1, place values from recordset into text
boxes
' in detail section.
If Me.FormatCount = 1 Then
For intX = 9 To intColumnCount
' Convert Null values to 0.
TempContractor = Me("Head" + Format$(intX))
' Replace underscores with periods (reversing what
cross tab query does with periods)
Contractor = ""
For i = 1 To Len(TempContractor)
If Mid(TempContractor, i, 1) = "_" Then
Contractor = Contractor & "."
Else
Contractor = Contractor & Mid(TempContractor,
i, 1)
End If
Next i
'ItemCombo = rstReport.Fields("itemcombo")
ItemCombo = rstReport.Fields("itemcombo")
Me("Unit" + Format$(intX)) = xtabCnulls(rstReport(intX
- 1))
' filter recordset to display current Contractor's
record for current Combo Item
Set rstTotals = dbsReport.OpenRecordset("SELECT * FROM
[qryBidtabulationStep2] WHERE Contractor = '" & Contractor & "' AND
[itemcombo] = '" & CStr(ItemCombo) & "'")
Me("Total" + Format$(intX)) =
rstTotals.Fields("TotalCharge")
ColumnTotals(intX) = ColumnTotals(intX) +
rstTotals.Fields("TotalCharge")
Me.WMTotal = rstTotals.Fields("WMTotalItemCharge")
TempWMTotal = Me.WMTotal
If Me("Total" + Format$(intX)) <> Me("Unit" +
Format$(intX)) * rstTotals.Fields("Quantity") Then
Me("Diff" + Format$(intX)) = Me("Unit" +
Format$(intX)) * rstTotals.Fields("Quantity")
Else
Me("Diff" + Format$(intX)) = ""
End If
rstTotals.Close
Next intX
WMTotalTotal = WMTotalTotal + TempWMTotal
' Hide unused text boxes in detail section.
For intX = intColumnCount + 1 To conTotalColumns
Me("Unit" + Format$(intX)).Visible = False
'Me("DLine" + Format$(intX)).Visible = False
Next intX
' Move to next record in recordset.
rstReport.MoveNext
End If
End If
End Sub