Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Need Help In Transfering Data From Access Query To New Excel File.


Hi,
  I need help in transfering data from access query to new excel file.

But i need it in code format, i need to write a code so that when i click a button in access form it should transfer query data to excel, it should be
book1 like when i open new excel.


And i am using DAO, but access doent take range methods.

If anyone of you know how to do this, can you please help me.


Veeresh




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Problem On Transfering Data From Excel To Access
I am transfering my datasheet from Excel to Access. Here is the code I used:

-------------------------------------------------------------------------------------
Dim appAccess as Access.Application
Set appAccess = New Access.Application

ActiveWorkbook.Names.Add:="TransferRange",RefersToLocal:=Range("D13:W" & Range("A65536").End(xlUp).Row)

appAccess.OpenCurrentDatabase "C:Documents and SettingssandringDesktopReport.mdb"

appAccess.DoCmd.TransferSpreadsheet acImport,_
    acSpreadsheetTypeExcel97, _
    "monthlyreport", _
    ActiveWorkbook.Path & "" ActiveWorkbook.Name, _
    False, "TransferRange"

appAccess.CloseCurrentDatabase
appAccess.Quit

MsgBox "Transfer Complete", vbOKonly, "Data Transfer"

End Sub

----------------------------------------------------------------------

When i run the code, the code paragraph from DoCmd to False, "TransferRange" became yellow and the arrow point to “False” line. I am wondering what the problem might be. Is that i put unmatched column name in my access datatable? or something else. Expert, please help.

Transfering Data From Excel Or Csv File To Sql Vb
Can any one suggest me how to teansfer data from excel or a csv file to sql server. I know this can be done using ado and reading the file and then inserting one row at a time..but i have like records in thousands and this slows the whole process..can anybody suggest me a good way probably with an example..thanx

Transfering Data From Access Table To Csv File
Hello to all of you helpers,

I am attemping to add code to an existing VB application to retrieve a table from an Access database and save the data as a csv file.

The database connection has already been opened by the program and I know how to construct the sql query. It will be this:

strSQL = "SELECT * from OutputDataTableDef"

now I need to get the recordset which will go something like this:

GetDataRecorset...,strSQL

I don't know how to construct this statement or how to open the csv file and copy the data to it.

I would like to thank you in advance for your help,
Shannon

Transfering Data Form A Data Grid To Excel
Hi guys.

I have a program in VB6 which load data from an access table into a data grid, now I need to trasfer that data in the grid to an excel sheet. How can I do this?.

Thanks in advance

Transfering Data Between Two Access DBs
Hello all,

I have two Access databases with same structure (i.e same tables). One is filled with some data while the other is totally blank.

What's the most optimized piece of code to transfer data from one DB to another using the "ADO" Connection and Recordset objects?

Regards

Insert New Row In Excel While Transfering Data!
Hi,

I am trying to transfer data from a MSHFlexiGrid to Excel sheet. I can bold the rows and the data on condition. I want to insert a blank row on condition. Can anyone help me ?
Below is the code.

VB Code:
'Copying data from Grid to ExcelFor intRow = 1 To ManuARGrid.Rows    For intCol = 1 To ManuARGrid.Cols        With ManuARGrid            wsXL.Cells(intCol + 3, intRow).Value = .TextMatrix(intRow - 1, intCol - 1)            strCellText = .TextMatrix(intRow - 1, intCol - 1)            Select Case strCellText Case "FinYear"        wsXL.Range("a" & intCol + 3).EntireRow.Font.Bold = True        wsXL.Range("a" & intCol + 3).EntireRow.Font.Color = RGB(0, 0, 0)        Case "Non-Current Assets:"        wsXL.Range("a" & intCol + 3).EntireRow.Font.Bold = True        wsXL.Range("a" & intCol + 3).EntireRow.Font.Color = RGB(0, 0, 0)End Select End WithNextNext 'Formating Excel celssFor intCol = 1 To ManuARGrid.Cols wsXL.Columns(intCol).AutoFit wsXL.Columns(intCol).Format NumberNext


What I want to do is insert a blank row below if it encountered "Non-Current Assets:"

Thanks

Transfering Msfgrid Data To Excel
all right guys .i should first thank u all for all the advices u have given :hack,martinliss,robdogg,rhinobull,joacim anderson,brucevde and evryone else!

my lecturers were really impressed at the complexity and appearance of my apllic.(of course the logic too!).now i have a few difficulties and they are:
in my design i created a visible menu and a toolbar but when i run the toolbar covers the menu.i tried to change the top and left properties but all went in vain.how can i make both the menu and toolbar be visible together.

the next is this i have a function that writes msflxgrid data to a file

VB Code:
Public Function GridExport(gridtoexport As Object, filename As String, Optional Delimiter As Variant, Optional EncloseStrings As Variant) As Boolean  On Error GoTo ErrHandler        Dim iNumRows As Integer    Dim iNumCols As Integer    Dim iFileNumber As Integer     If IsMissing(Delimiter) Then        Delimiter = vbTab    End If    If IsMissing(EncloseStrings) Then        EncloseStrings = ""    End If    iFileNumber = FreeFile    Open filename For Output As #iFileNumber    For iNumRows = 1 To _                gridtoexport.Rows - 1        gridtoexport.Row = iNumRows        For iNumCols = 0 To _                    gridtoexport.Cols - 1            gridtoexport.Col = iNumCols            'if it isn't the first column,            'put a delimiter before the value            If iNumCols > 0 Then                Print #iFileNumber, Delimiter;            End If            Print #iFileNumber, EncloseStrings & _                    gridtoexport.Text & EncloseStrings;        Next iNumCols        Print #iFileNumber, ""    Next iNumRows    GridExport = TrueErrHandler:If iFileNumber > 0 Then Close #iFileNumberMsgBox "File Save Success Saved as " & filenameEnd Function

this code courtesy martinliss and robdogg..
now i want to write this data directly to an excel sheet
can i just send <filename.xls> as an argument to filename variable? will that work .as right now i dont have a pc here to try that!!

in case its not possible to answer both the questions i will start a new thread for the second one

Transfering Data Between Excel Workbooks
Hi everyone

I need a bit of help, is it possible at the click of a button on a userform, to transfer data from a worksheet of the workbook holding the data to a new workbook?

Access Data To Excel Using CrossTab Query??
Hi ... I am trying to import Access data to excel woksheets using a crossTab query. I need to use a search criteria in excel. I have no clue to convert the crosstab query to excel VBA code. Can anyone help me with this ...

The Query looks like this :

TRANSFORM Sum(try2.Charge) AS SumOfCharge
SELECT try2.ServiceID, try2.ServiceDescription
FROM try2
GROUP BY try2.ServiceID, try2.ServiceDescription
PIVOT Format([DateOut],"yyyy");

try2 is another query:

SELECT tblService.ServiceID, tblService.ServiceDescription, tblCar_Service.DateOut, tblService.Charge
FROM (tblCar_Service INNER JOIN tblCar_Service_Details ON tblCar_Service.CarServiceID = tblCar_Service_Details.CarServiceID) INNER JOIN tblService ON tblCar_Service_Details.ServiceID = tblService.ServiceID;

Can anyone tell me how one canuse a crosstab query with excel. or can we make parameterized queries with crosstab.

Cheers, Nit

Paste Access Query Data Into Excel
I work a lot using Access & Excel (v2000).
I use Access to store data (imported from other systems) and Excel for reports.

Is there a way to push data from Access query into specific cell/range/sheet in a workbook?

I tried the TransferSpreadsheet macro in Access. but it seems it doesn't support export into specific range/sheet.

Thanks.

Transfering Excel Spreadsheet To Access Table
Transfering Excel spreadsheet to Access Table ...?

Query Data From Access By Writing A Code In Excel
Here is what I am doing - create a code in Excel to bring data from Access Database in the same folder. Two problems on the following code: 1) when I used double quote for DatePart , the quoted part (like "yyyy") is highlighted as compile error. 2) it also shows the problem in the line of " .Open, , 3, 3 "

I got this code from a friend and just make minor change and expect it to work propertly. It turned out i met these two problems. Please give me a hint how to fix it. Many thanks.

Code:


Sub Import2()


Dim cn As Object, rs As Object, myCallYear As String, myCallMonth As String
Dim MySql As String, dbfullname As String, myCnt As Long

dbfullname = "C:Documents and SettingsxyzDesktopFFR.mdb"
myCallYear = Sheets("Reference").Range("E13").Value 'Pass Year
myCallMonth = Sheets("Reference").Range("E14").Value 'Pass Month

MySql = "SELECT DatePart(''yyyy'',[TransactionTime]),DatePart('m',[TransactionTime]),[Category],[Subcategory],Sum([DollarSpend]),[TransactionTime]" & _
    "FROM tblExpense GROUP BY DatePart('yyyy',[TransactionTime]),DatePart('m',[TransactionTime]),Category,Subcategory" & _
    "Having DatePart("yyyy",[TransactionTime]) ='" & myCallYear & "'" & "AND DatePart("m",[TransactionTime]) ='" & myCallMonth & "'Order By DatePart("yyyy",[TransactionTime]), DatePart("m",[TransactionTime]);"

myCallYear = Empty
myCallMonth = Empty


Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" _
       & dbfullname & ";" 'Create DB connection
    
Set rs = CreateObject("ADODB.Recordset")
With rs
    Set .ActiveConnection = cn
    .Source = MySql 'Pass your SQL
    .Open , , 3, 3 '.Open , , adOpenStatic, adLockOptimistic
    myCnt = .RecordCount
    If myCnt > 0 Then
        .MoveLast: .MoveFirst
         'Pull data to first sheet, cells a1:RecordestCountRow & column 3 _
            3 fields in the sql pass
        Sheets("Data").Range(Cells(2, 14), Cells(myCnt + 1, 21)).CopyFromRecordset rs
    End If
    .Close
End With
cn.Close
Set rs = Nothing: Set cn = Nothing

End Sub

Transfering Access Record In Sql Data Base...
Assumig i have acces my_db.md and my_mdb.mdf (in instace named DVD377-14D9E48CSQLEXPRESS)
Access mdb have table named my_table with:

field1
field2
field3

i have same table named my_table in sql instance with same named record and same property of access mdb

i want to transfer all record from access table in sql db, record by record...

similiar:

rs.recorset1 of access in rs.recorset1 of sql db
rs.recorset2 of access in rs.recorset2 of sql db
rs.recorset3 of access in rs.recorset3 of sql db


...ecc

record by record becose during the export from access to sql i make various operation on single record...



Edited by - Geof on 1/13/2007 11:21:47 AM

Transfering Data From Visual Basic To Access 2000
Hello,

I have been coding in Vb for about a month and have come across a problem. I'm attempting to open up a txt file which reads data into vb and then inserts the data into access.

I get an error message which states 'run-time error 424 object required'. Can anybody help? - see code below

thank you


Private Sub Command1_Click()
Dim nom As String, wage As Single, hrs As Single
Dim dbMyDB As Database, rsMyRS As Recordset
Dim SQLStmt As String


Set dbMyDB = OpenDatabase("staff.mdb")
Set rsMyRS = dbMyDB.OpenRecordset("staff", dbOpenDynaset)


picPay.Cls
Open "staff.txt" For Input As #1
Input #1, nom, wage, hrs
picPay.Print nom; wage, hrs
Close #1
SQLStmt = "INSERT INTO staff "
SQLStmt = SQLStmt & "(nom, wage, hrs)"
dbMyDBConnection.Execute SQLStmt
dbMyDB.Close
Print "Complete"
End Sub

Writing An Access Query To Excel File (.xls)
Hi there!

I'm usin VBA to make applications in Access97, I want to run a query and get a result collection, and write the collection to a Excel file (.xls)
I found a function for it with a parameter xls but that is a year ago and I lost the note. may be some docmd.

Thanks for the help.

How To Import Excel Data From A Closed Excel File To Access Table?
Hi friends,
i have the following Excel sheet

     A B
1 BILL PAID
2 CM20 650.00
3 CM32 1750.12


 I want to import the same data into an Access table with the same field name.

Any help?

Thankx and regards

Haris


_____________________________________________________________________


Edited by - harisraz on 6/18/2006 1:33:00 AM

How To Deal With "out Of Memory" Problem When Transfering Data To Excel?
When I read data from excel or write a little data to excel using
Automation, everything is OK. But when I write a lot of data to
excel using Automation, it always causes "out of memory" error.
Anybody knows how to solve this problem? Thanks.

Copy Data From Excel File Into Ms Access
Can someone tell me how to copy the data from the excel file to Ms Access database
Pls show me the code
Thks

VB:How To Import The Data Of A Excel File To Access
Hi

I would like to develop an application in Visual Basic (both in VB.6 and
VB.NET) from where I could extract the data contained in a spreadsheet
(excel) to a Database in Access 2000.

Has anyone an idea how to do it so (which syntax to use ?)


Ed

How To Transfer Data From Access To An Excel File
Hi All,

This is my first post at this forum (friend recommended it).

I have recently started writing code for Access and Excel. My current project involves running a small database to store data and using an Excel spreadsheet to "Report" the data. Previously we used the spreadsheet alone saving multiple copies with each record in it. We want to keep using the spreadsheet as it has some complicated charts that I don't want to try and reproduce in Access.

I searched on the internet and found out how to use the ShellExecute API to open the correct file but now I need to transfer the data from the database to specific cells in the spreadsheet. What is the best way to do this?

Originally I tried to use variables and have the excel file reference the variables on opening but the spreadsheet could not "see"them. So now I wanted to write some code in the Access module that would enter the data into the cells in the Excel spreadsheet, as that way I can update the data in the spreadsheet if the user moves to a different record in the DB.

Thanks heaps

PS also is there a way to close the excel file from Access using VB, ie when the DB is closed?

Data Transfer From Text File To Excel && MS Access Table
I just learned how to copy data in a ADO recordset into Excel File using this link by Si_the_geek.
I also learned some Textfile manipulations from the links of dee-u & Pengate.

Thank you everyone.

Now I am wondering how to transfer the data
i) from a textfile (which is having ":" as delimiter) to access table
ii) from a textfile (which is having ":" as delimiter) to Excel File
ii) from a Excel file to an MS Access Table

I tried using the below code. No data was transferred. So its obviously incorrect

Text to Excel Code:
Dim fNo As Integer
    Dim sTemp As String
    fNo = FreeFile
   
    Open app.Path & "Text1.txt" For Input As fNo
        Do While Not EOF(fNo)
            Line Input #fNo, sTemp
        Loop
        oSheet.Range("A1").Value = sTemp
        oWorkbook.SaveAs App.Path & "TestBook.xls"
    Close fNo

I request the members show me how to do the above or point to some tutorial.
Thankyou.

Excel File Data Send In Access Database Through Vb Click
i have excel file and i want to send in access database through vb click.
plz help some one.
urgently.
thanx

Trying To Export Data Form Access To An Excel File, Getting Permission Denied Error
Basically, I have this application that Gets data from a table using a query, then it uses VBA to Export that data to an Excel spreadsheet.

Previously, this had worked perfectly before, but I had to make changes to it to seperate the data into two different groups based on a status of either OT or OTA.

So I moved the function from the main form to a pop-up form that has a combo box on it for the user to select a status type. I also changed the query to check that combo box to get the criteria for the query.

Now when I tried to export the data, it gives me a "Run Time Error 70: Permission Denied".

I have tried this with the application running on the server(Both before and after the changes) and on my PC(Which I am the admin of), and I get the same error. Here is the export code:


Code:
Private Sub cmdExport_Click()
Dim Response As Integer


Response = MsgBox("Do you want to Export all of the " & cboStatus _
& " Licensee data to the Excel file PublicUseOutput.xls? Click <Yes> to Continue or <No> to cancel the request", _
vbQuestion + vbDefaultButton2 + vbYesNo, "Export Licensee Data")
If Response = vbYes Then
ExportRequest
Else
MsgBox "Export Request Cancelled", vbInformation, "Export Cancelled"
End If
End Sub

Public Function ExportRequest() As String
On Error GoTo err_Handler

' Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Dim sTemplate As String
Dim sTempFile As String
Dim sOutput As String

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sSQL As String
Dim lRecords As Long
Dim iRow As Integer
Dim iCol As Integer
Dim iFld As Integer

Const cTabTwo As Byte = 2
Const cStartRow As Byte = 4
Const cStartColumn As Byte = 3

'DoCmd.Hourglass True

' set to break on all errors
Application.SetOption "Error Trapping", 0

' start with a clean file built from the template file
sTemplate = DLookup("TemplateLocation", "tblExcelLookUp")
sOutput = DLookup("PULocation", "tblExcelLookUp")
If Dir(sOutput) <> "" Then Kill sOutput
FileCopy sTemplate, sOutput

' Create the Excel Applicaiton, Workbook and Worksheet and Database object
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sOutput)
Set wks = appExcel.Worksheets(cTabTwo)
'sSQL = "SELECT tblImport.*, IIf([MailPrefence]='Personal',
'[MailingAddress],[EmpAddress]) AS PrefAddr, IIf([MailPrefence]
'='Personal',[City],[EmpCity]) AS PrefCity, IIf([MailPrefence]
'='Personal',[ST],[EmpST]) AS PrefST, IIf([MailPrefence]='Personal',
'[ZipCode],[EmpZipCode]) AS PrefZip, [FirstName] & " " & [Middle]
'& " " & [LastName] AS FullName FROM tblImport WHERE
'(((tblImport.MailPrefence)<>"none") AND ((tblImport.LicenseStatus)
'="Active"));" ' Commented out due to using a query instead
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryPublicUseExport", dbOpenSnapshot) ' Used qryPublicUse instead of sSQL



' For this template, the data must be placed on the 4th row, third column.
' (these values are set to constants for easy future modifications)
iCol = cStartColumn
iRow = cStartRow
If Not rst.BOF Then rst.MoveFirst
Do Until rst.EOF
iFld = 0
lRecords = lRecords + 1
Me.lblMsg.Caption = "Exporting record #" & lRecords & "!"
Me.Repaint

For iCol = cStartColumn To cStartColumn + (rst.Fields.Count - 1)
wks.Cells(iRow, iCol) = rst.Fields(iFld)

If InStr(1, rst.Fields(iFld).Name, "Date") > 0 Then
wks.Cells(iRow, iCol).NumberFormat = "mm/dd/yyyy"
End If

wks.Cells(iRow, iCol).WrapText = False
iFld = iFld + 1
Next

wks.Rows(iRow).EntireRow.AutoFit
iRow = iRow + 1
rst.MoveNext
Loop

DoCmd.Hourglass False
ExportRequest = "Total of " & lRecords & " records processed."
Me.lblMsg.Caption = "Total of " & lRecords & " records processed."

exit_Here:
' Cleanup all objects (resume next on errors)
On Error Resume Next
Set wks = Nothing
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Set rst = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
Exit Function

err_Handler:
DoCmd.Hourglass False
ExportRequest = Err.Description
Me.lblMsg.Caption = Err.Description
Resume exit_Here


End Function

Any thoughts?

What Would Be The Code In Visual Basic For Exporting Ms Access Table Data To Ms Excel File
what would be the code in Visual Basic for exporting ms access table data to ms excel file ...?

I Am Exporting An Access Query To Excel, How Can I Define The Excel Cell Size/format
I am using TransferSpreadsheet to Export a Query to Excel with a button from Access.

How can I define in Excel when I export it, the size of the cells, the type of letter (Arial, Bold), The Background color.

Private Sub Impacto_Click()
DoCmd.TransferSpreadsheet transfertype:=acExport, _
spreadsheettype:=acSpreadsheetTypeExcel9, _
TableName:="Impact", _
Filename:="C:Impact.xls", _
hasfieldnames:=True
End Sub

Can I Query Data From Multi Excel Tables And Insert Them Into Another New Excel Table
Hi everyone,

Can I query data from multi excel tables and insert them into another new excel table via VC?

i.e. I have excel table A, and excel table B, they have one same column "num"

I hope I can join these two tables into one new excel table via this public coulmn, all the steps should be finished via VC (please tell me if you have other suggestion about the program tool ^_^)

Seems that the function of "Microsoft query" in the Excel is OK, But I hope I can do a good UI and user don't need to write sql by himself, so it is better if you can tell some reference about how to query from muti-tables (I think it should be muti-datasource) and insert this result to another excel table,Thanks a lot :-)

AND how to implement it? please give me more doc if it is possible, Thanks!

I'm not familar with sql syntax about excel, could you please tell more about this? thanks!


Thanks
Lindsay

Run Access Query From Excel VBA
I'm wondering what the best way is to execute a query in Access and return that dataset back to Excel VBA.

Any suggestions?

Access Query--&gt;vb--&gt;excel
I have a query in access. i want to call the query in vb, obtain the result set, and send it to an excel file. the data environment is already set up.

this is what i have:
Private Sub btnGenZoneList_Click()
Select Case cboZone.Text
Case "Arlington"
MsgBox ("Arlington")
Case "Athens"
MsgBox ("Athens")
Exit Sub
End Select
End Sub

instead of the MsgBox, i want the result set to be sent a new excel sheet.

Thanks./

Query From Excel To Access
Hello,

I am trying to make a query from Excel 2007 into an Access 2007 database.

I use the following steps:

1. Get external data
2. From other sources
3. From microsoft query
4. Choose data source: MS Access database*
5. Select Options
6. Select Browse

In step 6 I can only select files with extension *.dsn or *dqy or *.oqy.
Since an Access database has an extension *.accdb or *.mdb, I cannot select any Access database!

Is there something I do wrong?

thanks a lot!

regards,
Marcel

Access Query From Excel
This is an add on to previous thread "excel-access with password"
(Still need help with that one also)
I open an access data base using excel, run a query, save into excel file, then close query.
Snag- The query is ran from a macro but needs data inputting to input boxes (criteria boxes), "Start Date" & "End Date". I want to able to able to set the "Start" and "End dates" by using input boxes in excel.
Code used so far is

Dim appaccess As New Access.Application
Const conpath As String = "filepath and name"
With appaccess
.OpenCurrentDatabase conpath
.DoCmd.RunMacro "Export query"
.CloseCurrentDatabase
End With


My desk is littered with books and examples but just can't get the right combination.

PLEASE SAVE MY MENTALLITY or not

Query Data From SAP R/3 Into Excel
Hi Everyone,
Looking for help on pulling data from SAP directly into Excel. I have the code to connect to SAP and to disconnect. My SQL statement is... strSQL = "SELECT EBELN FROM SAPR3.EKKO WHERE EKKO.BEDAT = '29-SEPT-04'"

I am now stuck as to how I get the results from this statement into excel. I am looking at about 50 records on average. Any help would be greatly appreciated.

Thanks
Chris

How To Query Data In Excel
I have some statement like this:
    Set rsCom = ImportData(App.Path & "data.xls", 2) ' 2: Sheet2
    
'rscom contains rows data in excel file

    rsCom.Find "Com_ID =1"
    rsCom.MoveFirst
    rsCom.Find "Year =2003"
I want find rows have Com_ID =1 AND Year=2003 but i can't
Why rsCom receives rows where Com_ID=1 not Year=2003?
help me! Thanks very much

Transfering From Excel To Sql Server
Hi

I would like to know what sort of a task it is transferring information from excel to sql server backend database. I have experience (good level) of using access and vb in access. I have used odbc to transfer from one excel book to another.

Any comments or method or considerations for data layout I would like to know.

Thanks for your comments.

Rob

Transfering Data
HI, I found the below code which is working great. I use it to match and transfer data from a long ugly file to a template each month. There are only certain columns of data that get transfered into the template so I edit the code and add a new modual for each columns of data that I need to tranfer. The problem is the number of columns to be transfer will change and so will the location, is there a way that I can have it match the column headings instead of column numbers, like its matching the the values in column A in the datasheet the to vaule in the template

Here is what I made these changes to the code but no luck. I idea I had was to make the columns were the data comes from a variable but I'm probly way off. here is the code that I changed. when I run it a get an error message "constant expresoin required"


Code:
Dim TCL As Range
Dim SCL As Range

Set TCL = Sheets("work").Range("B1")
Set SCL = Sheets("work").Range("B2")


Const FR = 2 'first row
Const tcm = 1 'column to match
Const tcp = TCL 'Target Column Location
Const scm = 1 'column to match
Const scp = SCL 'Source Column Location

Example of code when it works; see below


Code:
Option Explicit

Sub YTDTotalBM()
'code to run from the sheet shere changes are to be made
't = target = where data shoule be substituted
's = source = where data are found
Dim FirstCell As Range, LastCell As Range
Dim trng As Range, srng As Range, cell As Range, FoundCell As Range
Dim c As String

Const FR = 2 'first row
Const tcm = 1 'column to match
Const tcp = 4 'column mth Results
Const scm = 1 'column to match
Const scp = 4 'column mth Results

Sheets("Sales Managers").Activate

Set FirstCell = ActiveSheet.Cells(FR, scm)
Set LastCell = Cells(65536, scm).End(xlUp)
Set trng = Range(FirstCell, LastCell)

Set srng = Workbooks.Open("C:OCWSalesYTDData.xls").Worksheets(1).Columns(scm)

For Each cell In trng
Set FoundCell = srng.Find(cell, lookAT:=xlWhole)
If Not FoundCell Is Nothing Then FoundCell.Offset(0, scp - scm).Copy cell.Offset(0, tcp - tcm)
Next cell

ActiveWindow.Close
end sub

Transfering Data
Hi everyone!
i want to transfer files (and data) between different pc, so i wish to know how to find something about a way of cripthing the files and the way of formatting data.
Thenks

Transfering Data
Currently in my program i have a label with teh score contained within it. now when the tiemr runs out i want to hide this form and show the second and to show the score fromt he first label to one on the second form.
I haev tried to declare a variable and then in the timer thingy ensure the caption is copied to this, and then in the show the variable back to the second label but this isnt working. I probably havent declared it right.

Any ebtetr ideas are welcome, or teling me what and where to declare my scorevar as.
Cheers

Transfering Data From One Db To Another
How do you transfer data from one db to another?

Transfering Data
i would like to transfer info taken from a word document with visual basic code and transfer it to a word document without visual basic code.
eg:enter name
enter date

transfer to page

name:
date: <---without Vba code. Possible????

Also i was wondering what the command is to bring up the dialog box to choose a file to insert. I want a form that asks the user to insert a picture.

Thanks

Help Please {Access Query Results To Excel}
i am using vb code to access a database. in that code i am using a combo box that allows the user to choose what he/she would like to query by. i guess this brings about my question. once that have query the database to obtain the following results, you are able to view one by one each record that was obtained by the query. i am wondering is it possible to send the query results to MS excel. hopefully this makes sense.
Thanks a lot
Squeakie

Excel Sheet And Access Query
Hello, I've been trying to link an access query to a excel worksheet, but I can't figure out how.

I've tried to do it with the transfer spreadsheet action in a macro, but it only links a table, not a query.

the help mentions something about queries, but the link doesn't work.

Thanks,
BJ

Excel - Access Parameter Query
The problem - run an Access parameter query from Excel-97 using VBA. Any solution would be great. I can open the Access db and pass the parameters to an Access module but don't know how to pass the parameters to the query.

This code runs the Access macro "test macro" which in turn runs the query and prompts the user for two dates. I'd like to bypass the userform and have the dates entered from the spreadsheet. The dates are still variable, they just come from a different source.


""""Excel
Sub RunAccessSub()

Set appAccess = CreateObject("Access.Application.8")
appAccess.OpenCurrentDatabase "c:.... ooling.mdb", False
appAccess.Run "TDT", "12/12/01", "3/3/02"
Set appAccess = Nothing

End Sub



'''''Access
Sub TDT(start_time As String, end_time As String)

DoCmd.RunMacro "test macro"

End Sub

Thank you.

Export Access Query To Excel
We have an Access 2000 application that uses Docmd.TransferSpreadsheet to export a query to Excel. We use TransferSpreadsheet in several places with no problem. However, one query will not export properly on some PC's but does fine on others even though the data is the same.

The Access code looks like this:
Docmd.TransferSpreadsheet, acExport, acSpreadsheetTypeExcel9, "QueryName", "Path", True

Issues:
The query is relatively complex involving 6 other queries and 1 table.
All users have recent builds of Office 2000, SR1
All users have NT 4, SP6

The Big Issue:
The export works on all PC's with IE 5.5 or 6, but not with IE 5.0. I had one user get Computer Support to upgrade from IE 5.0 to 5.5 (support couldn't find 6.0???) and the export still didn't work.

I think that the problem is related to IE, but can't prove it.

Any ideas?

Excel && MS Access Query Question
Guys,
If anyone know why I am getting the following error message when I execute this script, I would love to know!!! The error message I am getting is as follows: "No value given for one or more required fields."

Now I know that the users last name I am searching on is in that Database, so I am not sure why I keep getting this error message. Well here is the code, please let me know what stupid mistake I made this time!!


Code:
Private Sub CommandButton1_Click()
Dim rsData As ADODB.Recordset
Dim szConnect As String
Dim szSQL As String

szConnect = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=i:desktopusers.mdb"

szSQL = "SELECT * From Prod_users WHERE LASTNAME = " & lname

Set rsData = New ADODB.Recordset
rsData.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

If Not rsData.EOF Then
Sheet1.Range("A2").CopyFromRecordset rsData
rsData.Close
With Sheet1.Range("A1:B1")
.Value = Array("Last Name", "Last Name")
.Font.Bold = True
End With
Sheet1.UsedRange.EntireColumn.AutoFit
Else
MsgBox "Error: No Records Returned.", vbCritical
End If

If CBool(rsData.State And adStateOpen) Then rsData.Close
Set rsData = Nothing
End Sub

The error is on this line:
Code:
rsData.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

Any help would be appreciated as always!!!! Thanks so much for any help on this issue.

Pasting An Access Query Into Excel
is there a way to do this without having to loop through a record set?

its too slow

is there a way to use an SELECT or INSERT query into a table directly?

Access Query To Excel Spreadsheet
Hello

I have an Access database which allows users to enter schedules for employees. I have put the information the information goes into a table and can be viewed from the form as a query. I have multiple records. (as below)

Date Venue Name Position
27/1/05 Home Joe Blow Permanent
27/1/05 Home Hansel Permanent
27/1/05 Home Gretel Casual
27/1/05 Home Barney Casual
27/1/05 Home Lisa Casual

There may be mutiple Venues for the same date. I want these to appear on a new row for every new venue/ date combination. Is there anyway I can take multiple records and place them into an excel spreadsheet set out as below.


Date Venue Permanent Casual
27/1/05 Home Joe Blow, Hansel Gretel, Barney, Lisa


Thankyou

Ps - I dont need the user to be able to do this themselves. I would like this to be able to be done after all records have been entered for the month.

Export Access Query To Excel
Could anyone help me with the code that would export a query to an existing Excel workbokk called "Vendor25K" and replace the data in the "Detail" sheet with the query data, then fire the Excel macros that are in this workbook?  The query name is "Vendors".  

Thank you in advance!!

Use Data From Access Query In VBA
Hello,

I have a query which contains the actual output I want from a database. But I don't want to present the data in a report, nor do I want to export the query results to a txt-file, I want to define how to write the txt file myself.

The question is: how do I access the query from the VBA code? Which variables do I have to define to retrieve for example the number of records of the query in VBA?

How do I get the value of a certain field of a certain record of the query?

Thanks a lot!

Jochen

Query Data From Access
I have a linktable in access linking to a dBASE file which contains the following records out of more then 50,000 records:
FILE NAME = SCF016
RECORD NOWORK SQRMWORK
1 WOL120519 1
2 WOL120519 2
i use query in access to query for this data using a simple sql statement and it can display out the 2 record in the datasheet screen.

But the problem was in visual basic program with the same SQL statement, i can only manage to retrieve 1 record count where the sqrmwork = 1. Below is the coding that i use. Did i make any mistake somewhere or Is there any better way to get the correct data out and not affect the data loading speed?

txtWOS="WOL120519"
strsql = " SELECT * FROM SCF016" _
&amp; " WHERE SCF016.NOWORK='" &amp; txtWOS _
&amp; "' AND SCF016.SQRMWORK&gt;0" _
&amp; " ORDER BY SCF016.SQRMWORK"
Set wos_scf016 = olddb.OpenRecordset(strsql, dbOpenSnapshot)
xcount = wos_scf016.RecordCount

Reading/Import Data From Excel 2003 File And Write/export To Access 2003 Database
I'm developing Database System using MS Access 2003
As the old data are all in Excel format, I'd like to add a function into the system so that operator import old data from Excel file into the Access 2003. But i do not know how to write data into Access Database using dataset object

I have write the follwing code to read data from Excel file:

Code: Public Sub import_from_excel()
Dim conn_excel As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=c:
eport
eport_10102006.xls;Extended Properties=Excel 8.0")

sqlcommand = String.Empty
sqlcommand = "Select * from ['Multiple PN$']"
Dim excel_adaptor As New OleDbDataAdapter(sqlcommand, conn_excel)
Dim excel_DS As New DataSet
excel_adaptor.Fill(excel_DS)

'For testing
Dim excel_DT As New DataTable
Dim f_ed As New excel_data
f_ed.Show()
excel_adaptor.Fill(excel_DT)
f_ed.dg_excel.DataSource = excel_DT
'conn_excel.Open()
conn_excel.Close()
       
End Sub

Copyright © 2005-08 www.BigResource.com, All rights reserved