updating an Access DB with Excel data via VBA (am I off track here?) | Bytes (2024)

Home Posts Topics Members FAQ

bbasberg

updating an Access DB with Excel data via VBA (am I off track here?) | Bytes (1) 24 New Member

Hello,

I have been struggling with this problem for DAYS and have googled my heart out as well as reading any books I could get my hands on but I cannot find any specific references to my problem. I have been able to successfully loop through a directory reading spreadsheets that insert records into an Access database. The spreadsheets in said directory are all of the same format but have different values in the cells. It's when I turned my attention to updating records that already exist in the Access DB that I have hit a brick wall.

I am NOT a VBA expert but have been trying to learn as quickly as possible. I'm sure I'm making lots of kludgy mistakes so I'll apologize in advance for the code that follows. I commented out other attempts I made to get it working. I am using DAO rather than ADO, and the application needs to be automated so I cannot have manual interventions hence the VBA code.

I'm hoping that it's just my neophyte status that is keeping it from working but maybe I cannot do it this way. In a nutshell, I don't know how to "tell" VBA that I want to compare an incoming cell in the Excel spreadsheet with the corresponding field in access to see if they are the same. If they are, of course I want to update not add a new record.

here is the code:

Expand|Select|Wrap|Line Numbers

  1. SubTestProc()
  2. DimlCountAsLong
  3. DimwbResultsAsWorkbook
  4. DimwbCodeBookAsWorkbook
  5. Application.ScreenUpdating=False
  6. Application.DisplayAlerts=False
  7. Application.EnableEvents=False
  8. OnErrorResumeNext
  9. SetwbCodeBook=ThisWorkbook
  10. WithApplication.FileSearch
  11. .NewSearch
  12. 'Remembertochangepathtolocalconditionsofriskgroup
  13. .LookIn="C:\DocumentsandSettings\basbergb\Desktop\usethisone_risk\pristine\access\IncomingRiskCandidateFiles"
  14. .FileType=msoFileTypeExcelWorkbooks
  15. .Filename="*.xls"
  16. If.Execute>0Then'Workbooksinfolder
  17. ForlCount=1To.FoundFiles.Count'Loopthroughall.
  18. SetwbResults=Workbooks.Open(Filename:=.FoundFiles(lCount),UpdateLinks:=0)
  19. DimdbAsDAO.Database,rsAsDAO.Recordset,rAsInteger,AnsAsInteger,myWSAsWorksheet,critAsString
  20. Setdb=OpenDatabase("C:\DocumentsandSettings\basbergb\desktop\usethisone_risk\pristine\access\risk.mdb")
  21. Setrs=db.OpenRecordset("CandidateRisk",dbOpenTable)
  22. SetmyWS=Sheets("CandidateRiskWorksheet")
  23. Dimrs1AsDAO.Recordset
  24. 'getallrecordsinatable
  25. 'r=2'startingrowintheworksheet
  26. 'DoWhileLen(Range("A"&r).Formula)>0
  27. 'DoWhiler<4
  28. 'rs1.FindFirst"title=myWS.Range('B7').Value"
  29. 'rs.FindFirst"CandidateRisk.title=bob"
  30. 'Debug.Printrs.Fields("title")
  31. 'Setrs1=db.OpenRecordset("select*fromCandidateRiskwheretitle='7'")
  32. rs1.FindFirst("title=7")
  33. Ifrs1.EOFThen
  34. 'Ifrs.NoMatchThen
  35. Withrs
  36. .AddNew'createanewrecord
  37. 'addvaluestoeachfieldintherecord
  38. .Fields("title")=myWS.Range("B7").Value
  39. .Fields("status")=myWS.Range("K7").Value
  40. .Fields("IDby")=myWS.Range("B11").Value
  41. .Fields("IPT_WGID")=myWS.Range("G11").Value
  42. .Fields("dateID")=myWS.Range("K11").Value
  43. .Fields("riskOwner")=myWS.Range("B14").Value
  44. .Fields("IPT_WGRO")=myWS.Range("G14").Value
  45. .Fields("dateAssigned")=myWS.Range("K14").Value
  46. .Fields("dateFirstPresented")=myWS.Range("K17").Value
  47. .Fields("ifThenPerf")=myWS.Range("C19").Value
  48. .Fields("sitPerf")=myWS.Range("C20").Value
  49. .Fields("LH_Perf")=myWS.Range("E21").Value
  50. .Fields("CQ_Perf")=myWS.Range("E22").Value
  51. .Fields("RHA_Perf")=myWS.Range("F23").Value
  52. .Fields("ifThenCost")=myWS.Range("C19").Value
  53. .Fields("sitCost")=myWS.Range("C20").Value
  54. .Fields("LH_Cost")=myWS.Range("E21").Value
  55. .Fields("CQ_Cost")=myWS.Range("E22").Value
  56. .Fields("RHA_Cost")=myWS.Range("F23").Value
  57. .Fields("ifThenSched")=myWS.Range("C19").Value
  58. .Fields("sitSched")=myWS.Range("C20").Value
  59. .Fields("LH_Sched")=myWS.Range("E21").Value
  60. .Fields("CQ_Sched")=myWS.Range("E22").Value
  61. .Fields("RHA_Sched")=myWS.Range("F23").Value
  62. .Fields("DAESriskFactor")=myWS.Range("B40").Value
  63. .Fields("reqRiskBasedOn")=myWS.Range("J40").Value
  64. .Update'storesthenewrecord
  65. EndWith
  66. Ans=MsgBox("CandidateRiskwrittentoAccessdatabase",vbInformation,"TransferredData")
  67. 'r=r+1
  68. 'Loop
  69. Else
  70. crit="7"
  71. rs.MoveFirst
  72. rs.Index="title"
  73. rs.Seek"=",crit
  74. MsgBoxrs!Title
  75. rs.Edit
  76. rs!Title=myWS.Range("B7").Value
  77. rs!Status=myWS.Range("K7").Value
  78. rs!IDby=myWS.Range("B11").Value
  79. rs!IPT_WGID=myWS.Range("G11").Value
  80. rs!dateID=myWS.Range("K11").Value
  81. rs!riskOwner=myWS.Range("B14").Value
  82. rs!IPT_WGRO=myWS.Range("G14").Value
  83. rs!dateAssigned=myWS.Range("K14").Value
  84. rs!dateFirstPresented=myWS.Range("K17").Value
  85. rs!ifThenPerf=myWS.Range("C19").Value
  86. rs!sitPerf=myWS.Range("C20").Value
  87. rs!LH_Perf=myWS.Range("E21").Value
  88. rs!CQ_Perf=myWS.Range("E22").Value
  89. rs!RHA_Perf=myWS.Range("F23").Value
  90. rs!ifThenCost=myWS.Range("C19").Value
  91. rs!sitCost=myWS.Range("C20").Value
  92. rs!LH_Cost=myWS.Range("E21").Value
  93. rs!CQ_Cost=myWS.Range("E22").Value
  94. rs!RHA_Cost=myWS.Range("F23").Value
  95. rs!ifThenSched=myWS.Range("C19").Value
  96. rs!sitSched=myWS.Range("C20").Value
  97. rs!LH_Sched=myWS.Range("E21").Value
  98. rs!CQ_Sched=myWS.Range("E22").Value
  99. rs!RHA_Sched=myWS.Range("F23").Value
  100. rs!DAESriskFactor=myWS.Range("B40").Value
  101. rs!reqRiskBasedOn=myWS.Range("J40").Value
  102. rs.Update
  103. Ans=MsgBox("Successfullyeditedtherecord",vbInformation,"Updatedvalues")
  104. EndIf
  105. rs.Close
  106. Setrs=Nothing
  107. db.Close
  108. Setdb=Nothing
  109. wbResults.CloseSaveChanges:=True
  110. NextlCount
  111. EndIf
  112. EndWith
  113. OnErrorGoTo0
  114. Application.ScreenUpdating=True
  115. Application.DisplayAlerts=True
  116. Application.EnableEvents=True
  117. EndSub

Thank you (so much) in advance for reading my post and hopefully steering me in the right direction.

P.S. I see that advice is often "link to excel from access" but I don't think that will do it for me in this case, right?

Thanks again.

Jan 4 '07

Subscribe Reply

11 updating an Access DB with Excel data via VBA (am I off track here?) | Bytes (2) 5754 updating an Access DB with Excel data via VBA (am I off track here?) | Bytes (3)

  • <
  • 1
  • 2

bbasberg

24 updating an Access DB with Excel data via VBA (am I off track here?) | Bytes (4) New Member

good idea.

Jan 7 '07 #11

reply

NeoPa

32,564 updating an Access DB with Excel data via VBA (am I off track here?) | Bytes (6) Recognized Expert Moderator MVP

Thanks for the reply Adrian. Even though it's almost 1 am here I had to try your suggestion. I'm wondering about it though (after I got an error) because riskIndex is an index in the Access database while the range for the excel spreadsheet (actually it's just one cell) is called STRrtitle. The field in the database is called rtitle. It is only the index that's called riskIndex. Also, I have another reference to rs.index that isn't commented out in a With...End With block a little further down.

I hope you have a chance to reply again. I am very grateful. I have finally started to lose my mind over this problem as it has been consuming me for over a week...
Sorry for all the related and confusing variable/index names.

Barbara

Almost 01:00 - mine was past 03:00 ;)
This of course, was prepared yesterday for a reply but I was running late for my nephew's surprise 18th birthday party so I had to rush out quickly.
I'm delighted that you've managed to sort out your problem on your own. If truth be told, that's always a better resolution as you learn better that way.
Not always practical or possible though.
Killer's advice is, as always, worth following. Debugging is a very important part of finding and fixing problems - please ask in here for tips if required.
The Locals window, for instance, can be very useful.
Anyway, this one's fixed so that's all good :)

Jan 7 '07 #12

reply

  • <
  • 1
  • 2

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

Similar topics

5 4464

Updating Linked Table - why is action query failing?

by: deko |last post by:

How to run action query against linked table? I have an Access 2003 mdb with an Excel 2003 Workbook as a linked table. When I attempt to run an action query against the linked table I get this error: Deleting data in a linked table is not supported by this ISAM. From what I understand, indexed sequential access method (ISAM) drivers are...

Microsoft Access / VBA

7 2509

Future of MS Access......

by: Ronnie |last post by:

I'm curious if anyone has any insights into what Microsoft has in store for ACCESS in current or future releases? I'm currently working on Access 2000 and haven't seen the newer versions. I'm curious if Microsoft will keep VBA or move ACCESS over to VB.NET or C#? Thanks.

Microsoft Access / VBA

6 3660

When should you upgrade access 97/vba applications?

by: Terry Bell |last post by:

We've had a very large A97 app running fine for the last seven years. I've just converted to SQL Server backend, which is being tested, but meanwhile the JET based version, running under terminal server, has suddenly started running very slowly. The network engineer has thrown up his hands and said "It's Access 97". I've checked out lots of...

Microsoft Access / VBA

2829

Controlling Excel from Access: Using Sendkeys to enter data into an Excel Input Box

by: Jack |last post by:

Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the user to key in a password into an input box, the password is compared to a a partciular cell on a hidden (xlVeryHidden) sheet and if it matches the...

Microsoft Access / VBA

37 5200

How will Access Survive

by: jasmith |last post by:

How will Access fair in a year? Two years? .... The new version of Access seems to service non programmers as a wizard interface to quickly create databases via a fancy wizard. Furthermore, why would you even continue to use Access as a backend when you have a much superior option in SQL express? What about as a future front-end...

Microsoft Access / VBA

25 2253

Is Access bogus, or is it me?

by: DFS |last post by:

I have a job to automatically import Excel data and post to database tables, via a point-click interface. Choose-file-and-it-does-the-rest kind of thing. Cient stores data in columns in his sheet (I told them it should be in rows, but that's another issue). Sometimes the sheet gets new columns added. At that point, Access/import spec...

Microsoft Access / VBA

1 5726

Switching between Access and Excel using code

by: garry.oxnard |last post by:

Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access database - containing a list of addresses. Sequence of events is = (1) Excel template opens in its default XXX.xls filename. (2) Code runs to save...

Microsoft Access / VBA

4 3332

Updating Access Report using Excel

by: somanyusernamesaretakenal |last post by:

What I am trying to achieve: Basically I have generated a report in access. This report needs to be updated using excel. (Updating the new data, not changing existing data) What I did was I imported the existing report into Excel (Tools – Office Links – Analyze It with MS Excel). Then I linked the report to the Excel file. (File – Get...

Microsoft Access / VBA

4 1934

Somewhat novice Access user, tripped up in a query problem

by: pokerboy801 |last post by:

OK, I will try to explain this as clearly and as concise as possible. I am using Access, which has three MS Excel Linked tables, to store call center metrics for reps. My Excel workbook has three separate worksheets, all linked to Access. I have a query that performs some minor calculations, not to hard, and will be ued to drive a report....

Microsoft Access / VBA

8111

Problem With Comparison Operator <=> in G++

by: Oralloy |last post by:

Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...

C / C++

8274

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

by: jinu1996 |last post by:

In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...

Online Marketing

1 7863

The easy way to turn off automatic updates for Windows 10/11

by: Hystou |last post by:

Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...

Windows Server

8140

Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

by: tracyyun |last post by:

Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...

General

6514

AI Job Threat for Devs

by: agi2029 |last post by:

Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...

Career Advice

5336

Couldn’t get equations in html when convert word .docx file to html file in C#.

by: conductexam |last post by:

I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...

C# / C Sharp

3776

Trying to create a lan-to-lan vpn between two differents networks

by: TSSRALBI |last post by:

Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

Networking - Hardware / Configuration

3795

Windows Forms - .Net 8.0

by: adsilva |last post by:

A Windows Forms form does not have the event Unload, like VB6. What one acts like?

Visual Basic .NET

1 2282

transfer the data from one system to another through ip address

by: 6302768590 |last post by:

Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

C# / C Sharp

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

To disable or enable advertisem*nts and analytics tracking please visit the page.

updating an Access DB with Excel data via VBA (am I off track here?) | Bytes (2024)
Top Articles
15 Best Sensory Bin Tables for Toddlers {+Sensory Table Ideas}
7 Best Postpartum Clothes That Are Ultra Comfy for New Moms
Funny Roblox Id Codes 2023
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Joi Databas
DPhil Research - List of thesis titles
Shs Games 1V1 Lol
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
fltimes.com | Finger Lakes Times
Detroit Lions 50 50
18443168434
Newgate Honda
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Justified Official Series Trailer
London Ups Store
Mflwer
Spergo Net Worth 2022
Costco Gas Foster City
Obsidian Guard's Cutlass
Marvon McCray Update: Did He Pass Away Or Is He Still Alive?
Mccain Agportal
Amih Stocktwits
Fort Mccoy Fire Map
Uta Kinesiology Advising
Kcwi Tv Schedule
What Time Does Walmart Auto Center Open
Nesb Routing Number
Olivia Maeday
Random Bibleizer
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Black Lion Backpack And Glider Voucher
Gopher Carts Pensacola Beach
Duke University Transcript Request
Lincoln Financial Field, section 110, row 4, home of Philadelphia Eagles, Temple Owls, page 1
Jambus - Definition, Beispiele, Merkmale, Wirkung
Ark Unlock All Skins Command
Craigslist Red Wing Mn
D3 Boards
Jail View Sumter
Birmingham City Schools Clever Login
Thotsbook Com
Funkin' on the Heights
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Vci Classified Paducah
Www Pig11 Net
Ty Glass Sentenced
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 5832

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.