Richard1980
Registered User.
- Local time
- Today, 19:25
- Joined
- Aug 13, 2012
- Messages
- 72
Hello there,
I am struggling trying to execute a function inside a Form_current event to display some stats.
The Function is this:
The code for the Form_Current event is this:
Very simple.
Well, the problem is when I move to a new record, a error message comes up: "Run-time error '94' - Invalid use of Null".
It is because the AircraftID is not populated at that time.
I tried to insert in the function code something like that:
but it doesn't work.
Any suggestion?
Thanks, bye.
Riccardo
I am struggling trying to execute a function inside a Form_current event to display some stats.
The Function is this:
Code:
Function FlightsByAircraft(Aircraft As Long) As Long
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Dim str As String
str = "SELECT * FROM tblFlights WHERE AircraftID = " & Aircraft
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(str)
If rst.RecordCount = 0 Then
FlightsByAircraft = 0
Else
rst.MoveLast
FlightsByAircraft = rst.RecordCount
End If
rst.Close
Set dbs = Nothing
Set rst = Nothing
End Function
The code for the Form_Current event is this:
Code:
Private Sub Form_Current()
txtStats1 = FlightsByAircraft(Me.AircraftID)
Very simple.
Well, the problem is when I move to a new record, a error message comes up: "Run-time error '94' - Invalid use of Null".
It is because the AircraftID is not populated at that time.
I tried to insert in the function code something like that:
Code:
If IsNull(Aircraft) then
exit function
else
.... (the DAO.Recordset code)
but it doesn't work.
Any suggestion?
Thanks, bye.
Riccardo