Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2007

Tip: Looking for answers? Try searching our database.

Change Cursor Location

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sarah - 08 Mar 2007 19:52 GMT
I have this code which appends data to an Excel worksheet.  After the
appending is done the cursor location is at the end of the last record
appended in the worksheet.  How can I programmatically move the cursor back
to let's say cell B2?

Here is my code:

Set Db = New ADODB.Connection
Db.CursorLocation = adUseClient
Db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Application.CurrentProject.FullName
Set xlApp = CreateObject("Excel.Application")
Set xlwbBook = xlApp.Workbooks.Open(strFile)
Set xlwsSheet1 = xlwbBook.worksheets(SourceName)
xlwsSheet1.Activate
       
SQL1 = "Select ProcessID, ColorCode1, Status, EWONo1, MCRNo1, ModYear1,
KitSeqNo, Zone1, Station1, KitIDNo1 " _
       & "From tblEWO Order by [KitTrackNo], [ProcessID];"

y = xlApp.ActiveCell.Column - 1
xlApp.ActiveCell.Offset(0, -y).SELECT
x = xlwsSheet1.Application.ActiveCell.Cells.Address
rs.CursorLocation = adUseClient
If rs.state = adStateOpen Then
       rs.Close
End If
rs.Open SQL1, Db
If rs.RecordCount > 0 Then
       rs.MoveFirst
       x = Replace(x, "$", "")
       y = Mid(x, 2)
       Set rng = xlwsSheet1.Range(x)
       xlwsSheet1.Range(x).CopyFromRecordset rs
End If
rs.Close

Thanks,

Sarah
Ralph - 08 Mar 2007 20:54 GMT
xlwsSheet1.Range("B2").Select

> I have this code which appends data to an Excel worksheet.  After the
> appending is done the cursor location is at the end of the last record
[quoted text clipped - 36 lines]
>
> Sarah
Sarah - 08 Mar 2007 22:04 GMT
That worked great!  Thanks you!

> xlwsSheet1.Range("B2").Select
>
[quoted text clipped - 38 lines]
> >
> > Sarah
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.