0
I’m finishing my improvement project and there’s something that intrigues me a lot.
I needed to make a report based on the result of an SQL query, which I even questioned in Export SQL query data to Excel, and now I need to do the opposite and import data from an excel spreadsheet for access.
As I don’t have much knowledge about VBA, many things I’ve done I’ve had to research a lot before. In all cases it has always appeared as an option to use the Docmd.TransferSpreadSheet. However every time I tried to use it excel returned an error message saying:
The "Transferirplanilha" command or action is not available now.
My question is the following: Can I use this command inside excel? Or it should be used only in Access?
In my case I have the DB created with Access, and a form created in excel to perform the registration of information in DB.
In this form I have a "Update Base" button, when the user clicks on the button he should, in theory, copy the data of a given spreadsheet into a BD table.
From my research the code wouldn’t be too complex, it would look something like this:
Private Sub atualizarbase_btn_Click()
Dim strXls As String
strXls = ThisWorkbook.Path & "\ATIVOS\ativos.xlsx"
DoCmd.TransferSpreadsheet acImport, , "ativos", strXls, True, "ativos!"
End Sub
How can I make it work?
The object
DoCmd
is exclusive to Access.– Marco
It’s not a difficult thing to solve, but I have some doubts about what you’re trying to do. 1 - This spreadsheet is always in the same place? 2 - You could not include the data directly in Access instead of the spreadsheet and then to Access?
– Marco
I ask this because in the case 1 you could simply create a linked table within Access and in case 2 you could make the tab
ativos
always received table dataativos
through a connection.– Marco
@Mark yes the spreadsheet will always be in the same place. But it can be replaced monthly. This asset spreadsheet contains all the employees of the company. Then every month a new spreadsheet will be generated with the data. This worksheet will be saved in the same place and with the same name (overwriting the previous one) and the new collaborators should be imported into the Access table. Since I already have a form that connects with the BD it would be interesting to just add a button on it to make the import.
– Humberto Faria
As this form will be used by other people, who do not have so much knowledge about BD, programming and etc, I would prefer that they do not need to use Access to import as it would avoid problems.
– Humberto Faria
Is that the way it was placed, it seems to me that you want the table in BD is always replaced by the data of the spreadsheet that is being used at the time.
– Marco
Make this inclusion through the spreadsheet will disturb for example in consistency, for example, not need to update or insert something that is already in the BD.
– Marco
And regarding the knowledge about BD and programming, this is irrelevant because you can make the Access file look like a system to be made this inclusion by a user-friendly interface.
– Marco