473,385 Members | 1,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Type mismatch on CopyFromRecordset Access

Hey everyone, I am having an issue when exporting a table from Access to Excel. I do not know why I keep getting an error, as I have used this code before. I'm assuming it's an easy fix and I'm just brain dead at this point of the day. Here's the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Staffing_Click()
  2.  
  3. Dim dbs As DAO.Database
  4. Dim objrst As DAO.Recordset
  5. Dim strXLStaffing As String
  6. Dim strStaff As String
  7. Dim xlApp As Object
  8. Dim xlWorkbook As Object
  9. Dim xlSheet As Object
  10.  
  11. strXLStaffing = "C:\Lynch\Staffing.xlsx"
  12. strStaff = "Daily Staffing List"
  13.  
  14. Set dbs = CurrentDb
  15. Set objrst = Application.CurrentDb.OpenRecordset(strStaff)
  16.  
  17. Set xlApp = CreateObject("Excel.Application")
  18. With xlApp
  19.     .Visible = False
  20.     .DisplayAlerts = False
  21.     Set xlWorkbook = Workbooks.Open(strXLStaffing)
  22.     Set xlSheet = xlWorkbook.Worksheets("Sheet2")
  23.     xlSheet.Activate
  24.     xlSheet.Range("A1").CopyFromRecordset strStaff
  25. End With
  26.  
  27. With xlApp
  28.     .Save
  29.     .Quit
  30. End With
  31.  
  32. Set objrst = Nothing
  33.  
  34. End Sub
I get the Run-time error '13' on the following line ({Edit} Line #24):
Expand|Select|Wrap|Line Numbers
  1. xlSheet.Range("A1").CopyFromRecordset strStaff
Any help would be greatly appreciated!

Thanks
Jan 18 '13 #1

✓ answered by TheSmileyCoder

Lets see....you want to copy a recordset, but pass a string to the function, and get a TYPE mismatch.

I will just leave that comment hanging and see if you can figure the rest out. If you truly can't, I will give the "solution" but I would much prefer for you to figure it out yourself and learn from it.

3 3132
TheSmileyCoder
2,322 Expert Mod 2GB
Lets see....you want to copy a recordset, but pass a string to the function, and get a TYPE mismatch.

I will just leave that comment hanging and see if you can figure the rest out. If you truly can't, I will give the "solution" but I would much prefer for you to figure it out yourself and learn from it.
Jan 18 '13 #2
Ahh yes, of course I was being brain dead. Just changed strStaff in the line to objrst and worked like a charm. Thanks!

Now I will have to revisit the early chapters in my Access 2007 VBA manual...
Jan 20 '13 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Good to see you caught it. I do know the feeling of staring myself blind at something, while thinking "grrr, this should be so simple but I just can't catch it".

Best of luck with you project.
Jan 20 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark | last post by:
Hi - I tried this in VS.Net, and also in the Web Matrix code below: - but I am getting a type mismatch error. The sql statement runs perfectly from within the Access Query Designer. Can anyone...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
1
by: Karl Irvin | last post by:
I copied the following code from the MS website. It compiles OK but gives a type mismatch message on the line that says: Set Flds = iConf.Fields What needs to be changed? Also can I use this to...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
1
by: Sunil Korah | last post by:
I am having some trouble with opening recordsets. I have used code more or less straight from the access help. But still I am getting some errors. I am unable to work out what exactly I am doing...
1
by: jodyblau | last post by:
I have a database which works fine until I create and MDE file. Once I create the MDE, when I open a particular form I get a "Type Mismatch" error. Because its an MDE file, I can't step through...
5
by: kjworm | last post by:
Hello Everyone, I have been fighting with a type mismatch error for many hours today and I can't seem to find what the problem is. Hopefully it is more than a missing apostrophe! I have isolated...
1
by: nckinfutz | last post by:
hello, I am having a problem with an access database. this is not my database and I did not create it, nor am I very good at access. however, I am a network engineer and that is why this problem...
1
by: crookward | last post by:
I usually have no problem identifying a type mismatch error, but this one's got me pulling my hair out. The mismatch error is pointing to line 269, which is a blank line, and it's also within an if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.