Nearly finished with my first VBA project and its looking quite good and people seem impressed. However, I have one little problem that I am sure could easily be cleaned up. At the min I have a button that opens a query and then instantly opens it in excel (very similar to the ‘analyse in excel’ pre-set button).
However, my problem is when the 'export' to excel takes place the file automatically takes the name of the query e.g. 'qryMakeFSPAtta inmentImportTab le'. However, after they have finished updating the data in the excel spreadsheet it needs to be imported back in under the name 'FSP Attainment Import'. I realise I could just tell people to rename the file, but you know and I know this would never be the case and I would get constant email's flying my way saying the import function doesn’t work. I know the code I have used isn’t the best as the query is opened when the button is pressed and stays open afterwards; this is a bit of a pain too. I have pasted my code below
Any help is greatly appreciated
Ste
However, my problem is when the 'export' to excel takes place the file automatically takes the name of the query e.g. 'qryMakeFSPAtta inmentImportTab le'. However, after they have finished updating the data in the excel spreadsheet it needs to be imported back in under the name 'FSP Attainment Import'. I realise I could just tell people to rename the file, but you know and I know this would never be the case and I would get constant email's flying my way saying the import function doesn’t work. I know the code I have used isn’t the best as the query is opened when the button is pressed and stays open afterwards; this is a bit of a pain too. I have pasted my code below
Code:
Private Sub cmdFSPFile_Click()
On Error GoTo ErrorHandler
DoCmd.OpenQuery "qryMakeFSPAttainmentImportTable", acViewNormal, acReadOnly
DoCmd.RunCommand acCmdOutputToExcel
CleanUpAndExit:
Exit Sub
ErrorHandler:
Call MsgBox("An error has been encountered" & vbCrLf & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Number: " & Err.Number, , "Error Deleting Record")
Resume CleanUpAndExit
End Sub
Ste
Comment