473,405 Members | 2,176 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,405 software developers and data experts.

update and delete single access record set via excel vba

I have this tool where employee information needs to be updated. I call in the MDB data to excel in one sheet. Now I use vlookup to see what is there and change it if needed.

I have tried some tricks however some thing seems to be wrong.. please help.
Expand|Select|Wrap|Line Numbers
  1. Sub update()
  2. Dim cn As Object
  3. Dim rs As Object
  4. Dim a As String
  5. strFile = "D:\temp excel\EIM.mdb"
  6. strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";"
  7. Set cn = CreateObject("ADODB.Connection")
  8. Set rs = CreateObject("ADODB.Recordset")
  9. cn.Open strCon
  10. a = Sheet2.Range("D4")
  11. strSQL = "SELECT * FROM EIM WHERE EIM.NBKID=" & a
  12. rs.Open strSQL, cn
  13.  
  14. strSQL = "UPDATE EIM SET EIM.Person#=('" & Sheet2.Range("D5") & "')WHERE EIM.NBKID=('" & Sheet2.Range("D4")
  15. cn.Execute strSQL
  16. End Sub

In the above code the file EIM has a table called EIM with NBKID and Person# fields.
Aug 2 '10 #1
5 3583
MikeTheBike
639 Expert 512MB
Hi

You have not said what 'some thing seems to be wrong' is??

Looking at the code my only guess (and in the absence of more info it is only a guess) is thet you try this mod

Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE EIM SET EIM.[Person#]=('" & Sheet2.Range("D5") & "') WHERE EIM.NBKID=('" & Sheet2.Range("D4") & "')"
Square brackets round Person#, a space between )WHERE and closing the last parentheses and apostrophe

??

ps what values are in D4 & D5

MTB
Aug 2 '10 #2
So sorry about not explaining the request clearly, I have this tool which allows people to update there information. I cannot use access to manipulate it as not all have access available and even it would be available I do not want to give them access to master database.

We have more than 500 employee's when ever some one moves out of one role to another or when someone leaves the organization. A manager has to request for hierarchy report which takes time to come.

Instead of going through that I want this tool to maintain record of all the employees, here nbkid is nothing but system id and person# is employee number or id.

I have a code to update the information however if someone needs to edit it due to some change to their role than I need another set of code.

By doing it in excel it is easy to manage - no additional training.

I have this button which should update the change made to the vaules updated in excel sheet. I dont want it to check if the record change, I just want it to use update.

In range D4 - I allow the user to enter there nbkid(system login id - unique and primary key) & with D5 - I allow the user to enter the changed person no(employee id)

When I run the above code I get error saying "No value given for one or more reqired parameters."
Aug 2 '10 #3
Thanks a ton - Problem resolved
Aug 2 '10 #4
MikeTheBike
639 Expert 512MB
@anand padia
Hi
When I run the above code I get error saying "No value given for one or more reqired parameters."
By the above code I assume you mean your origional post (not my suggestion?).

Also, I was asking what the actual values where/are (typically) in D4 & D5, not what they represented.

In addition, what is the data type of the NBKID and Person# fields in table EIM ??

If they are Numeric (as I now suspect) then you could try this
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE EIM SET EIM.[Person#]=(" & Sheet2.Range("D5") & ") WHERE EIM.NBKID=(" & Sheet2.Range("D4") & ")" 
Note: no apostrophies.

MTB
Aug 2 '10 #5
MikeTheBike
639 Expert 512MB
@anand padia
Glad you solved the problem.

Fore the record, would you mind letting use know what the solution was/is?

MTB
Aug 2 '10 #6

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

Similar topics

2
by: news.la.sbcglobal.net | last post by:
hi all i am trying to update or delete a row/record in table cptcodes the error i am getting is key column information is insufficient or incorrect to many rows were affected by update.... ...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
4
by: S. Graefner | last post by:
I have been unable to locate anywhere the answer to my problem. I would like to be able to download/import a single record. This record is stored in many different related (one to one) tables. I...
12
by: D. Shane Fowlkes | last post by:
This most likely belongs in another forum but I thought I'd start here. I have a COM Object written in VB6. The DLL will access MS Excel and use it's Object Library to write a customized report...
3
by: Rene | last post by:
Hi Proggies, i try to delete an excel worksheet but nothing happens (work on vb.net 2005) ..... xlSheet = xlApp.Sheets("Master") xlSheet.select xlSheet.delete also try
0
by: Slicemahn | last post by:
Hi Everyone! I have a spreadsheet in which I would need to update daily and have the new record added to a table in Access. Any ideas on writing code to update the d-base with the new data? ...
6
by: micksitup | last post by:
Hi all, I wish to find out how to export data to excel from access as follows: Select date range (which i understand how to do) The data from an entire table is sent to excel the filename...
4
by: viki1967 | last post by:
Hi everyone. With ASP I register in DB Access rows of one file excel; this procedure works but problem: Access record double rows of file excel. You can exclude from registration double rows ?...
1
by: accessvbanewbie | last post by:
I would like to export a recordset from access to excel but after each record is exported I want to insert a new row. The first recordset does this ok. However, the second recordset onwards does not...
6
BeemerBiker
by: BeemerBiker | last post by:
I can't get rid of a "deleted" record in a database. Even if I delete it the record shows back up the next time I do an update. The following code generates an error message when using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
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...

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.