UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> "no Current Record" On Recordset Containing Records, Access 2016    
 
   
dg_moore
post Oct 13 2019, 08:03 AM
Post#1



Posts: 344
Joined: 22-April 11



I'm getting a "No Current Record" error as indicated in the code below:
CODE
Dim rst1 As DAO.Recordset

   Set rst1 = db.OpenRecordset("tbl_TravEmailTemp")

   rst1.MoveLast  'To get recordcount

   If rst1.RecordCount = 0 Then
     MsgBox "No traveler email addresses found for this trip."
     Exit Sub
   End If

   DoCmd.Hourglass True

   rst1.MoveFirst

   Do While Not rst1.EOF
     MsgBox rst1!Email  <------  As diagnostic: Correctly returns value of first record
     strBCC = strBCC & rst!Email & "; "  <------ Returns "No Current Record" error
     rst1.MoveNext
   Loop


This one has me baffled - my lying eyes tell me there are 12 records in my recordset, MsgBox and Debug.Print display the value of the first record, but attempt to assign that value to a string variable throws "No current record" error.

Any suggestions??
Go to the top of the page
 
projecttoday
post Oct 13 2019, 08:09 AM
Post#2


UtterAccess VIP
Posts: 11,208
Joined: 10-February 04
From: South Charleston, WV


CODE
strBCC = strBCC & rst!Email & "; "

You left out the "1" in rst1.

--------------------
Robert Crouser
Go to the top of the page
 
Mickjav
post Oct 13 2019, 08:21 AM
Post#3



Posts: 76
Joined: 25-November 18



You should always use Option Explicit it would prevent that sort of error as when you compile the project it will show the error

mick

--------------------
All open code examples and free projects are only available from: Database Dreams
Go to the top of the page
 
dg_moore
post Oct 13 2019, 08:56 AM
Post#4



Posts: 344
Joined: 22-April 11



I'm getting too old for this. I should have seen that - thanks, gents.
Go to the top of the page
 
projecttoday
post Oct 13 2019, 08:57 AM
Post#5


UtterAccess VIP
Posts: 11,208
Joined: 10-February 04
From: South Charleston, WV


You're welcome.

--------------------
Robert Crouser
Go to the top of the page
 
GroverParkGeorge
post Oct 13 2019, 09:39 AM
Post#6


UA Admin
Posts: 36,064
Joined: 20-June 02
From: Newcastle, WA


Although Access, by default, does NOT set Option Explicit when you create new VBA modules, it is a really good idea to do so every time. Go to Tools-->Options in the VBE and check the option Require Variable Declaration.

Attached File  requireVariable.jpg ( 51.1K )Number of downloads: 0


When that setting is on, Access WILL now set Option Explicit.
Attached File  option_explicit.jpg ( 12.42K )Number of downloads: 0


With Option Explicit in all code modules, you'll get compile errors when you have missing Dims for variables, or misspelled variable names in your code. That'll head off problems like this one.
This post has been edited by GroverParkGeorge: Oct 13 2019, 09:40 AM

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th November 2019 - 07:42 AM