Excel 2007 :: Updating Access Using SQL In Macro
Mar 29, 2012
I have a CSV that I have a excel macro created to do some formatting and then export the data into Access. that part works. I also have it checking for duplicate entries and skipping them. The problem that i run into is that not all my duplicates are truly duplicate, there have been updates and now i need to update Access. I have 2 fields, my primary key which is what I'm primarily matching on and then I'm checking if its been updated by checking another field "Last Changed" If this field doesn't match then I need to update the record.
At this point I'm trying to use a SQL UPDATE and I now believe that i have it formatted correct but when it gets to a record that needs to be updated I get an error: Run-time error '-2147217887 (80040e21)': The changes you requested to the table were not successful because they would create duplicate values in the index, primary key or relationship. I'm not sure what I'm doing wrong. the only other thing i could think to do would be to check each field to see if it has changed and just run the query against that but I feel like i would run into the same issue.
This is how I'm connecting to Access:
Code:
strTableName = "TableName"
strDBLocation = "xxxxuserhomexxxxxxxxxxxxDatabaseDatabase Backend.accdb"
strConnect = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & strDBLocation & ";"
Set cn = New ADODB.Connection
cn.Open strConnect
Set rs = New ADODB.Recordset
rs.Open strTableName, cn, adOpenKeyset, adLockOptimistic, adCmdTable
And this is the Query I'm using:
Code:
strSQL = "UPDATE " & strTableName & " "
strSQL = strSQL & "SET [Work Order ID] = '" & Range("B" & r).Value & "', "
strSQL = strSQL & "[JOBSTATUS] = '" & Range("C" & r).Value & "', "
strSQL = strSQL & "[SUBSTATUS] = '" & Range("D" & r).Value & "', "
strSQL = strSQL & "[Job Status] = '" & Range("E" & r).Value & "', "
strSQL = strSQL & "[STATUSDATETIME] = #" & Range("F" & r).Value & "#, "
[Code] ..........
The SQL code sits in a loop with an IF so it shouldn't execute every time and I plan on once i get this working to revisit this code and try to optimize it but that is not a priority currently.
I'm using both Excel 2007 and Access 2007 on XP.
View 7 Replies
ADVERTISEMENT
Jan 5, 2012
In Excel 2007, I have a tables linked from Access 2007. I frequently delete and import a new set of data into Access, then refresh the Excel file. Most of the time this works, but I've noticed sometimes one column doesn't refresh (even though I can see it in Access). If I modify the field name in the Access query, then refresh the table in Excel the newly named field is added in the in the last column of the table with current data. The column that wasn't refreshing stays the same.
When I originally created the link in Excel, I added various columns with formulas, but do not edit the columns that are imported from Access.
View 6 Replies
View Related
May 24, 2012
I currently use a function very similar to this one with a SELECT query to return a field to excel. I have modified this into an UPDATE query to update a field.
I am getting errors at this point:
Code:
If adoRS.BOF And adoRS.EOF Then
DBNoteUpdate = "Value not Found"
Else
DBNoteUpdate = "Action Confirmation"
I believe this area of code was to trap the error that occurs when the lookup field name was not found in the table. I left it in because I still want to trap if the record I am trying to update is not found in the table.
Here is the full code:
Code:
Public Function DBNoteUpdate(RecordNumber As String, _
UpdateTableName As String, _
UpdateNote As String) As Variant
Dim adoRS As ADODB.Recordset
If adoCN Is Nothing Then SetUpConnection
[code].....
The code does work, in that the record is being sucessfully updated by the SQL statement, but its erroring at the point I described above with the error:
Code:
Runtime Error '3704':
Operation is not allowed when the object is closed.
how 'adoRS' is closed at that point because the call to close is right at the end of the function?
View 8 Replies
View Related
Jan 24, 2014
I've been trying to make this work for hours and hours and am finally giving up. Most of this code was found on the internet and I've attempted to make it work for my project but I keep getting errors. I use VBA with Excel quite often but never with Access before. Currently I am getting an "Object doesn't support this property or method" error at rs.Findfirst.
I have an excel worksheet that mimics the access table with five fields, an ID field, lastName, FirstName, DeptID (int), Email. I want to search the Access table for a match on the email field, and if it doesn't find the match, to add a new record using values typed into the excel sheet.
Code:
Sub UpdateDB()
Dim cn As Object
Dim rs As Object
[Code]....
View 2 Replies
View Related
Oct 27, 2013
I'm currently using Excel 2007 to get information from closed workbooks and updating my file.
First of all I create a table on selected range through "Insert table" command having something like this:
Then I have I piece of VBA code that tries to update every single cell of a column in this case it's updating %LD10 column:
But like you can see in first capture, the code updates every single cell with last value of variable fichero, having, at the end, the same value in whole column.
View 4 Replies
View Related
Mar 6, 2014
I have to complete his worksheet but now I am in a memory blank. I have the code set up but I guess I have been staring too much at this code...
I have 2 workbooks... One if for data entry and the other one is for a report.
So workbook1: the user will insert information on sheet1 and click a command button that will transfer the information on the next available row in Workbook2.
Workbook2 is strictly for report purpose. So all information transferred from book1 will be in book2.
I need a way, in book1, to have my userform (already set-up) to search for the matching information in my book2 Column A and update the information from my Book1 sheet2.
I have it set up this way:
VB:
Dim wbArchive As Workbook
Dim wsSrc, wsDst As Worksheet
Dim rngSrc, rngDst As Range
Dim rngReqNo As Range
Dim strReqNo As String
[Code] .....
View 2 Replies
View Related
Sep 12, 2010
I and my organization have many files created using Excel 2003. I have now upgraded to Excel 2007 and soon I discovered a huge problem.
- When opening a file using Excel 2007 that was created with Excel 2003 the links in that file is automatically updated even though I get the edit links dialog and choose not to update.
After searching for a solution on the Internet I realize that this is a problem that exist when Excel opens a file created in an earlier version. Microsoft has no solution.
I need to be in control of which links that are updated and not.
Going back to excel 2003 is not an option. Saving the source files in Excel 2007 is not an option.
View 5 Replies
View Related
Jun 5, 2007
When adding functions to the quick access toolbars in Excel 2007 sometime they do not have an associated icon with the function. The icon shows as a green circle. How to change the icons and also to have a selection of icons like you have had in previous versions of Excel?
View 5 Replies
View Related
Dec 12, 2011
I am attempting to create a template that will utilize data from an Access table, and allow the user to select the parameters in the Excel file. The amount of records in this table is slowing down the Excel file, and I would like to lessen the amount of data that is imported based on the user selection.
The Access table will have three columns:
Part Number|Line|Catalog Code
I would like to import all three columns, but allow the user to select the records imported based on the catalog code.
The users do not have read or write access to the sql tables, so I run an Access query at the end of each day to create an Access table that they can access.
I have 2007 versions.
View 1 Replies
View Related
Jul 11, 2013
I am familiar how to perform the task of bringing in an access table into excel, then using a data validation filter to control the data set in Excel 2003.
How to replicate this procedure in Excel 2007?
View 1 Replies
View Related
Oct 24, 2013
The current code is not working.
View 1 Replies
View Related
Mar 16, 2014
I have a large excel file with lots of data that it takes a long time to manipulate in excel. What I would like to do, is to import it in access, do some manipulations, and export it in excel again.
All these have to be automatic, so that the user does not do anything. Is it possible to do so through some macro?
View 1 Replies
View Related
Jan 29, 2008
I have an access database that has many queries and in order to speed it up I have a Macro in access that runs it in no time, but I need to be able to run the query in access via a trigger in Excel and have come up with the below, but it's not working.
View 9 Replies
View Related
Dec 7, 2012
I am not able to access *.rpt files in excel macro
By using this below mentioned codes am not able to open the files from folder.
Code:
fpath = "C:Documents and Settings est"
f = Dir(fpath & "*.xls")
Workbooks.Open Filename:=fpath & f
View 4 Replies
View Related
Nov 13, 2006
I am attempting to run a MS Ecel macro that is stored on a MS Excel shared file in a MS Ecel target file (locally stored on my C drive) from a VBA module in Ms Access. That is, from a code i want to open the .xls file that houses the macro, and then open the .xls file that i want to run the file in, and then run the macro.
Here is my situation: the file that houses the macro has the workbook hidden and causes in error.
if i unhide the workbook i get a Run-Time Error 91...object variable or With block variable not set.
if i hide the workbook the vba coding can't find the macro...run time error 1004
once again, i currently have an excel file that houses macro whose workbook is hidden.
does anyone know how this can be accomplished?
here is the ....
View 9 Replies
View Related
Jul 31, 2009
I manually copy a variable number of rows from an Excel worksheet and then paste/append them into an Access table.
I would like to have a macro for this to automate the process a bit, and I can always add the code to a button or menu item later.
Data setupRange starts at A11:X11
Number of rows to copy will vary depending on the data within the sheet
View 9 Replies
View Related
Nov 30, 2011
I have an intensive VB program I've written that the user kicks off by clicking a button. I update a particular cell near the button with progress numbers so they can see what's going on. (This calculation can take up to 10 minutes.)
Sometimes, though, the UI stops updating. I know the calculation is still running because it completes eventually.
I am guessing Excel is getting too many updates to its screen (i.e. that cell) to keep up with the calculation going on in another thread, so it just gives up on the updating.
Is there a way to force Excel to keep updating the screen? I'm willing to give up the 0.01% slowdown in exchange for continuing to see progress. I see no need for the VB calculation thread to hog out the screen updater.
Excel 2010 on Win XP Pro SP3
View 9 Replies
View Related
Jan 1, 2010
I have an Excel spreadsheet that I have developed into an over the top flight calculator/scheduling tool. I am using Excel because developing this prduct into a stand-alone program would be absolutely murder to get approved for use on my network.
Since Excel and Access has already been approved, I began coding this project there.
Now that my calculator functions are nearly complete, I am beginning to develop a database of airfields and other misc. flight data that I and others on my network can see and manipulate. To make my calculator funtion at 100% effectiveness, I will need to use VBA to open the Access DB and pull out specific data. I will also need it to open and display some Access pop-up forms that I have just developed. Does anyone know what code I would use for excel to display and retrieve Access' information?
View 9 Replies
View Related
Feb 1, 2010
I've just suceeded writing some code that collects data from one spreadsheet and places them in another sheet from where it is transferred to an Access 2007 table. It all works fine apart from one little thing: I can't find a way to close down the empty Access window after the data have been transferred.
View 2 Replies
View Related
Sep 27, 2009
I am at a point where I am running out of RAM for the 2BG allowed in 2007. Does anyone know if Microsoft has a later version of Excel that will allow me to grab onto 3GB? My file sizes are close to .5GB. It seems that I am always pushing the limit of what Microsoft can provide.
View 3 Replies
View Related
May 15, 2008
I want to write some code that runs everytime the workbook is initialized. I found out that the code should be placed in the following "Private Sub":
Private Sub Workbook_Open()
'My code
End Sub
I know that this code should be placed in the Private Module of the Workbook! I just can not find where is the Private Module of the Workbook in Excel 2007... =/
View 3 Replies
View Related
Nov 11, 2009
I need to create a new query that pulls data from a 2007 Access database into Excel 2007. When I invoke the 'From Microsoft Query' option after 'Data/From Other Sources', and then select 'MS Access Database*', the only file type presented is '*.mdb' . However, I need to pull from an '*.accdb' file type. I have both Office 2003 and Office 2007 installed.
View 8 Replies
View Related
Nov 30, 2007
The code to merge sheets to a master sheet runs great, however when I copy the code to the Personal.XLSB to have the macro available to use on every workbook I’m getting an error. The line of code is Application.Goto DestSh.Cells(1) and the error is Method ‘Goto of object’_Application’failed. This happen even if I create a new workbook with 3 sheets and only a few cells with information. The macro to mail the sheet works fine using the Personal XLSB.
View 11 Replies
View Related
Jan 6, 2008
I want to do simple calculation using Macro in MS Excel 2007..
All the data is in Sheet1 ( Which is 13a ), the calculation is in Sheet2 ( Which is work ) and the result of the calculation will come out in Sheet3 ( Which is result )..
Here is my coding..
View 12 Replies
View Related
Jul 10, 2012
I am trying to put together a standalone VBA macro that can easily be inserted into my financial models that allows me to quickly switch between two different printing setups - e.g. 8.5x 11 and 11x17 tabloid.
I also am using excel 2007.
View 2 Replies
View Related
Feb 4, 2014
A certain macro (or is it a VB script?) in an Excel 2007 spreadsheet has to be manually recalculated every time I open the file. The only way I've found to do this is to click in the formula bar and hit Enter, or else click the green check mark to accept the formula. The spreadsheet is set to recalculate automatically, so I do not understand why this is happening.
Another wrinkle is that I can't locate the specification/definition of the macro. I checked the Developer menu on the ribbon and looked in the Visual Basic and Macros lists, but could not see the definition of the macro in question. Another user created the spreadsheet but I am unable to contact him...
View 9 Replies
View Related
Nov 20, 2011
I am trying to rename a excel table from its file name after importing the data into the current sheet i am working in. Is there a method for going this? I can do it manually easily, but when I try to record myself within a macro, it still uses the file's previous name in the code before renaming it. Using Excel 2007.
View 5 Replies
View Related
Mar 11, 2012
I have a sheet with 500 rows and 20 columns. I want to put an input box and a button on a different sheet. What I would like to happen is that when you put the criteria in the input box and click the button it opens the form for the row corresponding to the criteria and allows you to edit the 20 columns. Excel 2007.
View 6 Replies
View Related
May 30, 2012
I have a file with 2 columns (A=headers, B=values x 38K rows) and need to transpose them to rows.
I found code to transpose a specified number of rows in a column (i.e. every 5th row in the column)...
BUT my columns have variable numbers of data points, because in the exported file any head with a null value was excluded.
So I need to start new rows with a specific text value of "Username" occurs in column A.
View 2 Replies
View Related
Jun 4, 2012
I have an excel workbook created in 2007, but now running in 2010. In the workbook I have a form Combo box with a macro assigned to it. When I click any value in the combo dropdown list the macro executes. In 2007 I could click the combo dropdown box and then press ESC to exit from the form control without executing the assigned macro. Similarly I could also click on any other cell to exit from the control without executing the macro.
But, in 2010 if I press ESC or click on any other cell the macro will execute. Sometimes I want to be able to exit from the combo box without executing the macro.
View 3 Replies
View Related