PC Review


Reply
Thread Tools Rate Thread

How do you set a recordset's bookmark?

 
 
Webtechie
Guest
Posts: n/a
 
      14th Sep 2009
Hello,

I have a userform in Excel. I am creating a recordset to an Access database.

I've created the recordset and can now populate my fields. However, I need
the user to be able to go back word and forward.

I am using a spin control on a userform to naviate. When the user clicks
up, I need to get the previous record.

I can't figure out how, using an ADO recordset on the , to get the previous
record.

dim iCurrentRecord as integer

'Create the recordset
'********************
Set rsGuestData = New ADODB.Recordset

'Is connection open?
'*******************
If myConnection Is Nothing Then
ConnectToDatabase
End If

'Get connection from the pool
'****************************
myConnection.Open

'Create SQL Statement
'********************
mySQL = "select * from tblGuest " _
& " where employeeid = " & thisEmployeeID _
& " and deptid = " & thisDept

Set rsGuestData.ActiveConnection = myConnection

iCurrentRecord = frmKeyLeads.spincontrol.value

With rsGuestData
.Source = mySQL
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open Options:=adCmdText
.bookmark = iCurrentRecord - errors
..moveprevious
End With


 
Reply With Quote
 
 
 
 
Ken Snell MVP
Guest
Posts: n/a
 
      15th Sep 2009
Is iCurrentRecord the value of the primary key in the recordset? If yes, you
don't use the Bookmark, instead you "move" the recordset to that record via
the Find method.

However, it appears that you want to move to the record previous to the
current record. There is no "order" in a recordset or table unless you
provide it via an Order By clause in the query used to create the recordset.
Your MySQL string does not include an Order By clause, so you have no
assurance of what is the order of data.

So,
(1) Add an ORDER BY clause to your MySQL string.
(2) Use the .Find method of the recordset to move the recordset to the
current record, using the value in iCurrentRecord variable if it's the
primary key.
(3) Use the .MovePrevious method to move to the record just before the
current record.

Or,
(1) Store the value of the previous record's primary key into a
variable.
(2) Add your new record.
(3) Use the .Find method of the recordset to move the recordset to the
previous record, using the value in this previous record variable.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



"Webtechie" <(E-Mail Removed)> wrote in message
news:16976FE5-F730-400F-934C-(E-Mail Removed)...
> Hello,
>
> I have a userform in Excel. I am creating a recordset to an Access
> database.
>
> I've created the recordset and can now populate my fields. However, I
> need
> the user to be able to go back word and forward.
>
> I am using a spin control on a userform to naviate. When the user clicks
> up, I need to get the previous record.
>
> I can't figure out how, using an ADO recordset on the , to get the
> previous
> record.
>
> dim iCurrentRecord as integer
>
> 'Create the recordset
> '********************
> Set rsGuestData = New ADODB.Recordset
>
> 'Is connection open?
> '*******************
> If myConnection Is Nothing Then
> ConnectToDatabase
> End If
>
> 'Get connection from the pool
> '****************************
> myConnection.Open
>
> 'Create SQL Statement
> '********************
> mySQL = "select * from tblGuest " _
> & " where employeeid = " & thisEmployeeID _
> & " and deptid = " & thisDept
>
> Set rsGuestData.ActiveConnection = myConnection
>
> iCurrentRecord = frmKeyLeads.spincontrol.value
>
> With rsGuestData
> .Source = mySQL
> .CursorLocation = adUseClient
> .CursorType = adOpenDynamic
> .LockType = adLockOptimistic
> .Open Options:=adCmdText
> .bookmark = iCurrentRecord - errors
> .moveprevious
> End With
>
>



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      15th Sep 2009
"Webtechie" <(E-Mail Removed)> wrote in message
news:16976FE5-F730-400F-934C-(E-Mail Removed)...
> Hello,
>
> I have a userform in Excel. I am creating a recordset to an Access
> database.
>
> I've created the recordset and can now populate my fields. However, I
> need
> the user to be able to go back word and forward.
>
> I am using a spin control on a userform to naviate. When the user clicks
> up, I need to get the previous record.
>
> I can't figure out how, using an ADO recordset on the , to get the
> previous
> record.
>
> dim iCurrentRecord as integer
>
> 'Create the recordset
> '********************
> Set rsGuestData = New ADODB.Recordset
>
> 'Is connection open?
> '*******************
> If myConnection Is Nothing Then
> ConnectToDatabase
> End If
>
> 'Get connection from the pool
> '****************************
> myConnection.Open
>
> 'Create SQL Statement
> '********************
> mySQL = "select * from tblGuest " _
> & " where employeeid = " & thisEmployeeID _
> & " and deptid = " & thisDept
>
> Set rsGuestData.ActiveConnection = myConnection
>
> iCurrentRecord = frmKeyLeads.spincontrol.value
>
> With rsGuestData
> .Source = mySQL
> .CursorLocation = adUseClient
> .CursorType = adOpenDynamic
> .LockType = adLockOptimistic
> .Open Options:=adCmdText
> .bookmark = iCurrentRecord - errors
> .moveprevious
> End With



Am I right in thinking that iCurrentRecord is basically a record number --
not a key value, but an ordinal position in the recordset? Depending on the
CursorType and provider, you may well be able to assign it directly to the
recordset's AbsolutePosition property, and therby position the recordset to
that record:

With rsGuestData
.Source = mySQL
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open Options:=adCmdText

' ...

.AbsolutePosition = iCurrentRecord

End With


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
Webtechie
Guest
Posts: n/a
 
      15th Sep 2009
Ken,

I went to the microsoft site to study up on recordsets. It said the .find
could not be used with a variable.

I could store the primary key (current record), find it in the recordset and
then moveprevious. But how would I do that if I can't use variables?

Tony

"Ken Snell MVP" wrote:

> Is iCurrentRecord the value of the primary key in the recordset? If yes, you
> don't use the Bookmark, instead you "move" the recordset to that record via
> the Find method.
>
> However, it appears that you want to move to the record previous to the
> current record. There is no "order" in a recordset or table unless you
> provide it via an Order By clause in the query used to create the recordset.
> Your MySQL string does not include an Order By clause, so you have no
> assurance of what is the order of data.
>
> So,
> (1) Add an ORDER BY clause to your MySQL string.
> (2) Use the .Find method of the recordset to move the recordset to the
> current record, using the value in iCurrentRecord variable if it's the
> primary key.
> (3) Use the .MovePrevious method to move to the record just before the
> current record.
>
> Or,
> (1) Store the value of the previous record's primary key into a
> variable.
> (2) Add your new record.
> (3) Use the .Find method of the recordset to move the recordset to the
> previous record, using the value in this previous record variable.
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
> http://www.accessmvp.com/KDSnell/
>
>
>
> "Webtechie" <(E-Mail Removed)> wrote in message
> news:16976FE5-F730-400F-934C-(E-Mail Removed)...
> > Hello,
> >
> > I have a userform in Excel. I am creating a recordset to an Access
> > database.
> >
> > I've created the recordset and can now populate my fields. However, I
> > need
> > the user to be able to go back word and forward.
> >
> > I am using a spin control on a userform to naviate. When the user clicks
> > up, I need to get the previous record.
> >
> > I can't figure out how, using an ADO recordset on the , to get the
> > previous
> > record.
> >
> > dim iCurrentRecord as integer
> >
> > 'Create the recordset
> > '********************
> > Set rsGuestData = New ADODB.Recordset
> >
> > 'Is connection open?
> > '*******************
> > If myConnection Is Nothing Then
> > ConnectToDatabase
> > End If
> >
> > 'Get connection from the pool
> > '****************************
> > myConnection.Open
> >
> > 'Create SQL Statement
> > '********************
> > mySQL = "select * from tblGuest " _
> > & " where employeeid = " & thisEmployeeID _
> > & " and deptid = " & thisDept
> >
> > Set rsGuestData.ActiveConnection = myConnection
> >
> > iCurrentRecord = frmKeyLeads.spincontrol.value
> >
> > With rsGuestData
> > .Source = mySQL
> > .CursorLocation = adUseClient
> > .CursorType = adOpenDynamic
> > .LockType = adLockOptimistic
> > .Open Options:=adCmdText
> > .bookmark = iCurrentRecord - errors
> > .moveprevious
> > End With
> >
> >

>
>
>

 
Reply With Quote
 
Webtechie
Guest
Posts: n/a
 
      15th Sep 2009
Dirk,

Thank you, thank you and thank you!

That worked.



"Dirk Goldgar" wrote:

> "Webtechie" <(E-Mail Removed)> wrote in message
> news:16976FE5-F730-400F-934C-(E-Mail Removed)...
> > Hello,
> >
> > I have a userform in Excel. I am creating a recordset to an Access
> > database.
> >
> > I've created the recordset and can now populate my fields. However, I
> > need
> > the user to be able to go back word and forward.
> >
> > I am using a spin control on a userform to naviate. When the user clicks
> > up, I need to get the previous record.
> >
> > I can't figure out how, using an ADO recordset on the , to get the
> > previous
> > record.
> >
> > dim iCurrentRecord as integer
> >
> > 'Create the recordset
> > '********************
> > Set rsGuestData = New ADODB.Recordset
> >
> > 'Is connection open?
> > '*******************
> > If myConnection Is Nothing Then
> > ConnectToDatabase
> > End If
> >
> > 'Get connection from the pool
> > '****************************
> > myConnection.Open
> >
> > 'Create SQL Statement
> > '********************
> > mySQL = "select * from tblGuest " _
> > & " where employeeid = " & thisEmployeeID _
> > & " and deptid = " & thisDept
> >
> > Set rsGuestData.ActiveConnection = myConnection
> >
> > iCurrentRecord = frmKeyLeads.spincontrol.value
> >
> > With rsGuestData
> > .Source = mySQL
> > .CursorLocation = adUseClient
> > .CursorType = adOpenDynamic
> > .LockType = adLockOptimistic
> > .Open Options:=adCmdText
> > .bookmark = iCurrentRecord - errors
> > .moveprevious
> > End With

>
>
> Am I right in thinking that iCurrentRecord is basically a record number --
> not a key value, but an ordinal position in the recordset? Depending on the
> CursorType and provider, you may well be able to assign it directly to the
> recordset's AbsolutePosition property, and therby position the recordset to
> that record:
>
> With rsGuestData
> .Source = mySQL
> .CursorLocation = adUseClient
> .CursorType = adOpenDynamic
> .LockType = adLockOptimistic
> .Open Options:=adCmdText
>
> ' ...
>
> .AbsolutePosition = iCurrentRecord
>
> End With
>
>
> --
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
>
> (please reply to the newsgroup)
>

 
Reply With Quote
 
Ken Snell MVP
Guest
Posts: n/a
 
      15th Sep 2009
Yes, you can use a variable in a Find method, for example:

..Find "PrimaryKeyFieldName = " & NameOfNumericVariable
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"Webtechie" <(E-Mail Removed)> wrote in message
news:71A3FF9D-D564-4224-833A-(E-Mail Removed)...
> Ken,
>
> I went to the microsoft site to study up on recordsets. It said the .find
> could not be used with a variable.
>
> I could store the primary key (current record), find it in the recordset
> and
> then moveprevious. But how would I do that if I can't use variables?
>
> Tony
>
> "Ken Snell MVP" wrote:
>
>> Is iCurrentRecord the value of the primary key in the recordset? If yes,
>> you
>> don't use the Bookmark, instead you "move" the recordset to that record
>> via
>> the Find method.
>>
>> However, it appears that you want to move to the record previous to the
>> current record. There is no "order" in a recordset or table unless you
>> provide it via an Order By clause in the query used to create the
>> recordset.
>> Your MySQL string does not include an Order By clause, so you have no
>> assurance of what is the order of data.
>>
>> So,
>> (1) Add an ORDER BY clause to your MySQL string.
>> (2) Use the .Find method of the recordset to move the recordset to
>> the
>> current record, using the value in iCurrentRecord variable if it's the
>> primary key.
>> (3) Use the .MovePrevious method to move to the record just before
>> the
>> current record.
>>
>> Or,
>> (1) Store the value of the previous record's primary key into a
>> variable.
>> (2) Add your new record.
>> (3) Use the .Find method of the recordset to move the recordset to
>> the
>> previous record, using the value in this previous record variable.
>>
>> --
>>
>> Ken Snell
>> <MS ACCESS MVP>
>> http://www.accessmvp.com/KDSnell/
>>
>>
>>
>> "Webtechie" <(E-Mail Removed)> wrote in message
>> news:16976FE5-F730-400F-934C-(E-Mail Removed)...
>> > Hello,
>> >
>> > I have a userform in Excel. I am creating a recordset to an Access
>> > database.
>> >
>> > I've created the recordset and can now populate my fields. However, I
>> > need
>> > the user to be able to go back word and forward.
>> >
>> > I am using a spin control on a userform to naviate. When the user
>> > clicks
>> > up, I need to get the previous record.
>> >
>> > I can't figure out how, using an ADO recordset on the , to get the
>> > previous
>> > record.
>> >
>> > dim iCurrentRecord as integer
>> >
>> > 'Create the recordset
>> > '********************
>> > Set rsGuestData = New ADODB.Recordset
>> >
>> > 'Is connection open?
>> > '*******************
>> > If myConnection Is Nothing Then
>> > ConnectToDatabase
>> > End If
>> >
>> > 'Get connection from the pool
>> > '****************************
>> > myConnection.Open
>> >
>> > 'Create SQL Statement
>> > '********************
>> > mySQL = "select * from tblGuest " _
>> > & " where employeeid = " & thisEmployeeID _
>> > & " and deptid = " & thisDept
>> >
>> > Set rsGuestData.ActiveConnection = myConnection
>> >
>> > iCurrentRecord = frmKeyLeads.spincontrol.value
>> >
>> > With rsGuestData
>> > .Source = mySQL
>> > .CursorLocation = adUseClient
>> > .CursorType = adOpenDynamic
>> > .LockType = adLockOptimistic
>> > .Open Options:=adCmdText
>> > .bookmark = iCurrentRecord - errors
>> > .moveprevious
>> > End With
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternative to recordset bookmark? deko Microsoft Access 4 23rd Jan 2008 05:09 PM
List Box & Subform -Recordset bookmark? =?Utf-8?B?S2FvbGk=?= Microsoft Access Getting Started 0 21st Sep 2006 02:14 PM
RecordSet Bookmark Property scott Microsoft Access Form Coding 3 21st May 2006 02:41 AM
Is there a way to know where the bookmark in a DAO.recordset is? Niklas Östergren Microsoft Access 7 23rd Dec 2004 07:40 AM
Replacement for Recordset Bookmark? Wayne Wengert Microsoft VB .NET 3 14th Jun 2004 04:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:53 PM.