Log in

View Full Version : Identifier under cursor is not recognized



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!

jonh
07-28-2016, 04:12 PM
Your form doesn't have a control or recordset field called sort_order.


Not sure why you are using a loop to find a null record. You can specify null in the query.

You are using ADO. DAO is generally the better option for Access.

jlinkster15
07-28-2016, 04:27 PM
Thanks for the response, John. After I posted this thread I realized my example database (where I'm pulling all the code) was using a query to build the form and the query pulled in the SORT_ORDER. I thought the form was pulling directly from a table, which didn't have the SORT_ORDER. So, when I built my own form I was pulling directly from a table. I have since created a query...

As for the null, I'm not sure why it's there... How would you specify null in the query?

Also, what's the difference between ADO and DAO?

jonh
07-28-2016, 04:43 PM
WHERE somefield is null
or
WHERE somefield is not null

You are pretty much always better off spending more time writing more complex sql than vba.


There isn't much difference between DAO and ADO. But DAO is Access's default. You don't need to set a reference.

For lots of cases you only need
currentdb.execute mySQL
currentdb.openrecordset mySQL

which uses DAO.

You generally only use ADO to connect to another type of database or for coding outside of Access.