po****@abv.bg wrote:
In my report called rptStockFlow i have the products
underlined with red if balance is not equal to in - out:
Const conNormal = 400
Const conHeavy = 900 ' exra bold
Private Sub Detail_Format(C ancel As Integer, FormatCount As
Integer)
If Me![balance] <> Me!In - Me!Out Then
Me!balance.Font Weight = conHeavy
Me!balance.Fore Color = 32768
Else
Me!balance.Font Weight = conNormal
Me!balance.Fore Color = 0
End If
If Me![balance] <> Me!OnStore Then
Me!OnStore.Font Weight = conHeavy
Me!OnStore.Fore Color = 255
Else
Me!OnStore.Font Weight = conNormal
Me!OnStore.Fore Color = 0
End If
End Sub
is it possible in the Onopen event of the report to create
some code that sends a warning message on the screen,that something is
wrong with the balance of the goods ?
What you might want to do is run a quick query in the onopen event on
the recordsource. I'm not sure if newer versions of access, when
opening a report, allow an argument to be passed to it like a form does
(OpenArgs). In 97, it doesn't. So you may want to store the filter to
the report in a variable. For example, lets say the form is called
CallRpt. It has the command
Docmd.OpenRepor t "SomeRpt",, ,"ID = 123"
You can store the "ID = 123" to a text box, invisible, on CallRpt named
FilterStr.
Let's say the report recordsource is
Select * From Accounts
You could then do something like this in the OnOpen event
Dim rst As DAO.Recordset
Dim strSQL As STring
'create SQL statement and get the filter from the form CallRpt
strSQL = Me.Recordsource & "Where " & Form!CallRpt!Fi lterStr & _
" And Balance <> (In-Out)"
Set rst = Currentdb.openr ecordset(strSQL ,dbopensnapshot )
If rst.recourcount > 0 then
msgbox "Look out, something is wrong here"
endif
rst.close
set rst = Nothing
Note, if you have a filter (Where clause) or OrderBy clause in the
Recordsource (the OrderBy is never needed in a report but this may be a
general query), you'll need to adjust for that. Ex:
Select * From Accounts Where Year = 2005 Order By AccName
You'll want to add the additional filter and remove the OrderBy so it
looks like
Select * From Accounts Where Year = 2005 and ID = 123 And
Balance <> (In-Out)