jlinkster15
07-28-2016, 01:56 PM
Hey all,
I realize there was another thread on here titled with the same error phrase, however that one was solved miraculously by sleep and a reboot. lol I'm afraid I don't have it that easy.
I'm pretty new to coding and I can't seem to get past this one bit.
I'm creating a form and I'd like to have a text box reference the previous entry. Here is the code in for my module, "basCommonCode";
Public Function PreviousSagMillDischarge(ByVal p_datSagDate As Date, ByVal p_intSortOrder As Integer) As Double
On Error GoTo Error_PreviousSagMillDischarge
Dim strSQL As String
Dim rstPreviousSagMillDis As ADODB.Recordset
Set gcnnMillReports = Application.CurrentProject.Connection
strSQL = "SELECT SAG_MILL_DISCHARGE, SAG_DATE, SORT_ORDER"
strSQL = strSQL & "FROM (tblSAG LEFT JOIN tblSHIFT ON"
strSQL = strSQL & "(tblSAG.SHIFT = tblSHIFT.SHIFT))"
strSQL = strSQL & "WHERE tblSAG.SAG_DATE < " & Format(p_datSagDate, gstrDateFormat) & " "
strSQL = strSQL & "UNION"
strSQL = strSQL & "SELECT SAG_MILL_DISCHARGE, SAG_DATE, SORT_ORDER "
strSQL = strSQL & "FROM (tblSAG LEFT JOIN tblSHIFT ON"
strSQL = strSQL & "(tblSAG.SAG_DATE = " & Format(p_datSagDate, gstrDateFormat) & " "
strSQL = strSQL & "AND tblShift.SORT_ORDER < " & p_intSortOrder & " "
strSQL = strSQL & "ORDER BY tblSAG.SAG_DATE DESC , tblSHIFT.SORT_ORDER DESC;"
Set rstPreviousSagMillDis = New ADODB.Recordset
rstPreviousMillDis.Open strSQL, gcnnMillReports, adOpenKeyset
PreviousSagMillDischarge = 0
With rstPreviousSagMillDis
If .EOF Then
Else
If IsNull(![SAG_MILL_DISCHARGE]) Then
While Not .EOF And IsNull(![SAG_MILL_DISCHARGE])
.MoveNext
Wend
End If
PreviousSagMillDischarge = ![SAG_MILL_DISCHARGE]
End If
End With
rstPreviousSagMillDis.Close
Set rstPreviousSagMillDis = Nothing
Set gcnnMillReports = Nothing
Exit_PreviousSagMillDischarge
Exit Function
Error_PreviousSagMillDischarge:
MsgBox "PreviousSagMillDischarge" & vbCrLf & vbCrLf & "Error # " & Err.Number & vbCrLf & vbCrLf & Err.Description, _
vbOKOnly + vbExclamation, CurrentDb().Properties("AppTitle").Value
Resume Exit_PreviousSagMillDischarge
End Function
And here's the code in my form, "Form_frmMillControl";
Private Sub SAG_MILL_DISCHARGE_GotFocus()
If (IsNull(Me.SAG_DATE) Or IsNull(Me.SHIFT)) Then
Me.txtSAG_MILL_DISCHARGE_PREV1 = 0
Else
Me.txtSAG_MILL_DISCHARGE_PREV1 = PreviousSagMillDischarge(Me.SAG_DATE, Me.SORT_ORDER)
End Sub
When I try to run the form, the form code pops up, the last SORT_ORDER is highlighted and when I look at the definition of SORT_ORDER it tells me the "Identifier under cursor is not recognized".
I've basically just tried to copy this code from someone else and modify it to make it my own, but obviously I'm missing a basic step. When I look at the definition for SORT_ORDER in my reference code, it tells me "Cannot jump to 'SORT_ORDER because it is in the library, which is not currently referenced."
Please help!
I realize there was another thread on here titled with the same error phrase, however that one was solved miraculously by sleep and a reboot. lol I'm afraid I don't have it that easy.
I'm pretty new to coding and I can't seem to get past this one bit.
I'm creating a form and I'd like to have a text box reference the previous entry. Here is the code in for my module, "basCommonCode";
Public Function PreviousSagMillDischarge(ByVal p_datSagDate As Date, ByVal p_intSortOrder As Integer) As Double
On Error GoTo Error_PreviousSagMillDischarge
Dim strSQL As String
Dim rstPreviousSagMillDis As ADODB.Recordset
Set gcnnMillReports = Application.CurrentProject.Connection
strSQL = "SELECT SAG_MILL_DISCHARGE, SAG_DATE, SORT_ORDER"
strSQL = strSQL & "FROM (tblSAG LEFT JOIN tblSHIFT ON"
strSQL = strSQL & "(tblSAG.SHIFT = tblSHIFT.SHIFT))"
strSQL = strSQL & "WHERE tblSAG.SAG_DATE < " & Format(p_datSagDate, gstrDateFormat) & " "
strSQL = strSQL & "UNION"
strSQL = strSQL & "SELECT SAG_MILL_DISCHARGE, SAG_DATE, SORT_ORDER "
strSQL = strSQL & "FROM (tblSAG LEFT JOIN tblSHIFT ON"
strSQL = strSQL & "(tblSAG.SAG_DATE = " & Format(p_datSagDate, gstrDateFormat) & " "
strSQL = strSQL & "AND tblShift.SORT_ORDER < " & p_intSortOrder & " "
strSQL = strSQL & "ORDER BY tblSAG.SAG_DATE DESC , tblSHIFT.SORT_ORDER DESC;"
Set rstPreviousSagMillDis = New ADODB.Recordset
rstPreviousMillDis.Open strSQL, gcnnMillReports, adOpenKeyset
PreviousSagMillDischarge = 0
With rstPreviousSagMillDis
If .EOF Then
Else
If IsNull(![SAG_MILL_DISCHARGE]) Then
While Not .EOF And IsNull(![SAG_MILL_DISCHARGE])
.MoveNext
Wend
End If
PreviousSagMillDischarge = ![SAG_MILL_DISCHARGE]
End If
End With
rstPreviousSagMillDis.Close
Set rstPreviousSagMillDis = Nothing
Set gcnnMillReports = Nothing
Exit_PreviousSagMillDischarge
Exit Function
Error_PreviousSagMillDischarge:
MsgBox "PreviousSagMillDischarge" & vbCrLf & vbCrLf & "Error # " & Err.Number & vbCrLf & vbCrLf & Err.Description, _
vbOKOnly + vbExclamation, CurrentDb().Properties("AppTitle").Value
Resume Exit_PreviousSagMillDischarge
End Function
And here's the code in my form, "Form_frmMillControl";
Private Sub SAG_MILL_DISCHARGE_GotFocus()
If (IsNull(Me.SAG_DATE) Or IsNull(Me.SHIFT)) Then
Me.txtSAG_MILL_DISCHARGE_PREV1 = 0
Else
Me.txtSAG_MILL_DISCHARGE_PREV1 = PreviousSagMillDischarge(Me.SAG_DATE, Me.SORT_ORDER)
End Sub
When I try to run the form, the form code pops up, the last SORT_ORDER is highlighted and when I look at the definition of SORT_ORDER it tells me the "Identifier under cursor is not recognized".
I've basically just tried to copy this code from someone else and modify it to make it my own, but obviously I'm missing a basic step. When I look at the definition for SORT_ORDER in my reference code, it tells me "Cannot jump to 'SORT_ORDER because it is in the library, which is not currently referenced."
Please help!