LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Retrieve and update 1 record at a time

I'm not sure how complicated this is, but thought it be worth asking...

I created a macro in excel using ADO to retrieve records from an
Access database (code below). My db table is called tblSales and has 2
fields: saleID, flag (flag datatype=True/False, with a default of False).
Currently the macro is pulling all saleIDs and storing them into Sheet2. I
want to modify the macro to only pull one row record at a time and at the
same time update the flag field of the current record to True. The reason
for the flag is so when there are multiple users, a SaleID will only be
retrieved once. Since we are pulling only 1 record at a time, the SaleID
will only be stored in cell A1, Sheet2 each time. Therefore, the excel sheet
will only display the current record at a time. I hope this makes sense, my
code current code is below. I am new to programming and have been stuck with
this one for awhile now. Thank you to anyone who can provide me with
assistance!


Sub GetRecord()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim WSOrig As Worksheet
Dim sSql As String

Set WSOrig = ActiveSheet

sSql = "SELECT saleID FROM tblSales"
sSql = sSql & " WHERE Flag=False"

MyConn = "C:\SalesDB.mdb"

Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open MyConn
End With

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open Source:=sSql, ActiveConnection:=cnn, _
CursorType:=AdForwardOnly, LockType:=adLockOptimistic, _
Options:=adCmdText

Worksheets("sheet2").Range("A1").CopyFromRecordset rst

rst.Close
cnn.Close

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
record update VBA form Roy Gudgeon[_2_] Excel Discussion (Misc queries) 0 March 15th 10 04:27 PM
want to record date for each time I update a file - Excel 2007 PattyR Excel Discussion (Misc queries) 2 June 3rd 09 08:18 PM
want to record date for each time I update a file PattyR Excel Discussion (Misc queries) 2 May 27th 09 05:40 AM
retrieve and update data from a dbf file alfonso gonzales Excel Programming 0 October 2nd 04 11:57 PM
Code to Update a Record No Name Excel Programming 1 January 29th 04 10:02 PM


All times are GMT +1. The time now is 09:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"