Referencing a value produced by a query in VBA (1 Viewer)

  • Thread starter Deleted member 8621
  • Start date
D

Deleted member 8621

Guest
I am tyring to set a variable to a value produced in a field by a query. I can't get the reference correct.
My goal is to take the value of a field on a form and check it against the value in the query. The query value is the last record for a specific store. The sloppy code (I'm new at this) that I have so far is:

Private Sub Text5_GotFocus()
On Error GoTo modOpenfrmMeterData_Err

Dim crec As String
Dim lrec As String
Set newqry = New ADODB.Recordset
Set new = newqry.Open qryStoreLastRec

crec = [Serial Number]
lrec = Recordset.qryStoreLastRec![Serial Number]

MsgBox lrec
' If crec = lrec Then
' MsgBox "This is the last record for your store"
' End If

DoCmd.OpenForm "frmMeterData", acNormal, "", "", , acNormal
DoCmd.RepaintObject acForm, "frmMeterData"

modOpenfrmMeterData_Exit:
Exit Sub

modOpenfrmMeterData_Err:
MsgBox Error$
Resume modOpenfrmMeterData_Exit

End Sub

Thanks for your help in advance.
matthew
 

Travis

Registered User.
Local time
Yesterday, 17:54
Joined
Dec 17, 1999
Messages
1,332
Dim crec As String
Dim lrec As String
Set newqry = New ADODB.Recordset
newqry.Open qryStoreLastRec

crec = "Serial Number"
lrec = newqry.Fields(crec)
 

Users who are viewing this thread

Top Bottom