473,395 Members | 1,452 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,395 software developers and data experts.

Access 2003-How to export a table and then reimport it later

I am working on an HR database for my work. I need to be able to "update" this database once it goes live but the powers that be don't want me to see the salaries. So my boss wants me to create a macro that allows HR to export the salary table and replaces the salary fields with bogus numbers. Then once I am done doing what ever I have to do he wants another macro that reimports that data.

I can export the data to an external database (using TransferDatabase function) and change the data, my problem is reimporting the data. Every import function I have found that is built in creates a New table and doesn't update the original table. I figure I am going to have to write code to do a sql update but I am not quite sure how to do this.

External database I am exporting to: h:\salary-rate.mdb.
Table name in both databases: Salary-Rate
Fields in Salary-Rate:
EmployeeID
EffectiveDate
Salary
HourlyRate
GradeNum
PromotionNotes


Any help you could give me is MUCH appreciated!
Dec 9 '08 #1
6 1523
ChipR
1,287 Expert 1GB
Not tested, but try something like this:

Expand|Select|Wrap|Line Numbers
  1. Set dbSource = DBEngine.OpenDatabase("h:\salary-rate.mdb")
  2. set records = dbSource.OpenRecordset("Salary-Rate)
  3.  
  4. 'may want DoCmd.SetWarnings False
  5.  
  6. while not records.eof
  7.     strSQL = "UPDATE Salary-Rate SET Salary = " & records!Salary _
  8.      & " WHERE EmployeeID = " & records!EmployeeID
  9.  
  10.    DoCmd.RunSQL strSQL
  11.  
  12.    records.MoveNext
  13. wend
  14.  
  15. 'and DoCmd.SetWarnings True
  16.  
  17.  
Dec 10 '08 #2
I keep getting a syntax error in my update statement. I have tried it numerous different ways and I am not sure what the correct syntax should be.

This is the last version I tried:
strSQL = "Update Salary-Rate SET Salary = rstSalaryRate!Salary WHERE EmployeeID = rstSalaryRate!EmployeeID"

I am sure I am missing some kind of ', &, or ".

I have also tried Me.EmployeeID = rstSalary![EmployeeID].

Any suggestions as to the correct syntax?
Dec 10 '08 #3
ChipR
1,287 Expert 1GB
Your record!fieldname is a variable, and so it has to be evaluated before it's inserted into the string. The & basically means + for strings. Try to make sure it looks like my code. You need the & even if it's all on one line.
Dec 10 '08 #4
I am getting it to work now "sort of". My statement is below:
strSQL = "Update SalaryRate SET Salary = " & rstSalaryRate!Salary & ", HourlyRate = " & rstSalaryRate!HourlyRate & " WHERE EmployeeID = " & rstSalaryRate!EmployeeID & " and EffectiveDate = " & rstSalaryRate!EffectiveDate & ""

I don't get a syntax error any more but no records are being updated. If I removed the " and EffectiveDate = " & rstSalaryRate!EffectiveDate & "" part rows are updated. But an employee could have several records because they will get a new record everytime they get a raise. This database will keep their history. I have a feeling it has to do with the date format but again what I am trying isn't working.

Any more suggestions would be much appreciated!

Thanks!
Dec 10 '08 #5
ChipR
1,287 Expert 1GB
Dates in the SQL string have to be surrounded by #, that's just how SQL does it. So if rstSalaryRate!EffectiveDate is a date use:

EffectiveDate = #" & rstSalaryRate!EffectiveDate & "#"

Strings, on the other hand need to be surrounded by " or '. So if it's a string use:

EffectiveDate = """ & rstSalaryRate!EffectiveDate & """"
Two " in a row in a string makes one " in the resulting string.
or
EffectiveDate = '" & rstSalaryRate!EffectiveDate & "'"
That's single quote, double quote & ... & double quote, single quote, double quote.
Dec 10 '08 #6
I got it work. Thank you for your help. I understand how it works but the syntax gets me everytime! :)
Dec 11 '08 #7

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

Similar topics

1
by: Wayne Aprato | last post by:
I have a client who is running several Access 97 databases that I have written for them. They are about to upgrade to Access 2003. Is the default file format of Access 2003 still Access 2000 the...
7
by: Wayne Aprato | last post by:
I have several Access 2003 mde databases. When I try to open them in Access 2002 I get the following error: "The Visual Basic for Applications project in the database is corrupt." ...
28
by: Neil Ginsberg | last post by:
I have a client who is using Access 2002/2000 (the database itself is written in 2000), and is considering migrating to Access 2003. Any recommendations on whether Access 2003 is worth the migrate,...
2
by: Johnny Meredith | last post by:
Hi all, I'm interested in getting the Access Developer's edition. Here's my question: where do I go to get it? At Microsoft, there's a Access 2003 Developer's Extensions package, as well as...
8
by: deko | last post by:
Is it possible to develop an Access app in Access 2003 that will run on Access 2000? Is it just a matter of selecting "Access 2000" from the Default File Format drop down list on the Advanced Tab...
10
by: Lauren Wilson | last post by:
Ok I have searched the MS website for info on this. I am totally confused. If I want to deploy an Access 2003 app and allow my users to run it using Access 2003 Runtime, where do I get the...
4
by: RM | last post by:
Had VS .Net 2002 installed on W2k Server SP3 and supported a number of web sites. Installed VS .Net 2003 on Friday and now all web sites using .Net & MS ACCESS get this strange error upon open. ...
5
by: Ecohouse | last post by:
I'm using VB and an Access 2003. The db was originally created in Access 2000, but the computer had to have things reinstalled and now has Access 2003. So I was wondering if there are any...
6
by: Donald Grove | last post by:
I do programming in Access 2000 and 2003. I don't have a copy of 2003 myself, though. I have read about the adp software that comes with Access 2003, that converts an application to an access...
3
by: Bruce | last post by:
I have a number of Access 2000 format databases on a Windows 2003 server. For some reason I can no longer compact these databases directly on the server using Access 2003. Access 2000 seems to...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
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...
0
tracyyun
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...

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.