Chace said:
Okay, I compiled the following code with no problems identified,
however it is still getting hung up at the line designated below.
Thanks so much for the help....this is driving me crazy.
Function IPLHazApplicability(ctl As Control, intHazIPLID As Integer)
As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim strSQL As String
Dim strSQL2 As String
Dim strHazardType As String
Dim intHazTypeID As Integer
Dim intHazTypeIPLsum As Integer
Dim intHazardID As Integer
Set db = CurrentDb
strHazardType = ctl.Name
intHazardID = [Forms]![frm_Hazards]![HazardID]
Select Case strHazardType
Case "chk_FL"
intHazTypeID = 1
Case "chk_EX"
intHazTypeID = 2
Case "chk_MD"
intHazTypeID = 3
Case "chk_EN"
intHazTypeID = 4
Case "chk_RX"
intHazTypeID = 5
Case "chk_TX"
intHazTypeID = 6
Case "chk_IN"
intHazTypeID = 7
End Select
If ctl = -1 Then
Set rs = CurrentDb.OpenRecordset("tbl_IPLHazTypeApplicability")
rs.AddNew
rs![HazIPLID] = intHazIPLID
rs![HazTypeID] = intHazTypeID
rs.Update
rs.Close
Set rs = Nothing
Else
strSQL = "Select * from tbl_IPLHazTypeApplicability where
HazIPLID=" & intHazIPLID & " AND HazTypeID=" & intHazTypeID
Set rs = CurrentDb.OpenRecordset(strSQL)
Debug.Print strSQL
rs.MoveFirst
rs.Delete
rs.Close
Set rs = Nothing
End If
intHazTypeIPLsum = DSum("[IPL Credit]", "[Query4]", "([HazID]=
[Forms]![frm_Hazards]![HazardID] And [Exist])=-1 And [HazTypeID]=" &
intHazTypeID)
strSQL2 = "SELECT tbl_HazardConsequences.*,
tbl_HazardConsequences.HazardID, " & _
"tbl_HazardConsequences.HazardTypeID FROM tbl_HazardConsequences " & _
"WHERE (((tbl_HazardConsequences.HazardID])=" & intHazardID & ") AND
" & _ "((tbl_HazardConsequences.HazardTypeID)=" & intHazTypeID & "));"
'Code will not go past line below, although it does NOT highlight
yellow Set rs2 = CurrentDb.OpenRecordset(strSQL2)
rs2![MitigFreq] = [Forms]![frm_Hazards]![cbo_InitFreq] * 10 ^
-intHazTypeIPLsum
rs2.Update
rs2.Close
Set rs2 = Nothing
[Forms]![frm_Hazards]![subfrm_HazardConsequences].Requery
End Function
I see two problems with that SQL statement, and I wonder if one of them
could be the problem :
strSQL2 = "SELECT tbl_HazardConsequences.*,
tbl_HazardConsequences.HazardID, " & _
"tbl_HazardConsequences.HazardTypeID FROM tbl_HazardConsequences " & _
"WHERE (((tbl_HazardConsequences.HazardID])=" & intHazardID & ") AND
" & _ "((tbl_HazardConsequences.HazardTypeID)=" & intHazTypeID & "));"
First, there's an extraneous, unmatched right quare bracket (]) on the
end of
"WHERE (((tbl_HazardConsequences.HazardID])
My guess is that's the culprit, but also you have the fields HazardID
and HazardTypeID included twice in the result set. Try this:
strSQL2 = _
"SELECT tbl_HazardConsequences.* " & _
"FROM tbl_HazardConsequences " & _
"WHERE (HazardID=" & intHazardID & ") AND (" & _
HazardTypeID=" & intHazTypeID & ");"
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)