![]() |
How do I write From Excel 2003 to Access 2000?
I'm trying to write some VBA Code so that when a User opens an Excel
Spreadsheet it logs it so that we know what reports are being used. I've found several examples of code but Ican't seem to get any of them to work (even talk to Access). So I'm not sure how to go about handling this. The Code I've been trying is as follows (I pulled this from another website): '' Purpose : Access Log File : Record process activity '' Written : 25-Sep-2001 by Andy Wiggins - Byg Software Ltd '' Notes : Needs a reference to DAO 3.5 '' Sub ALF(pStr_Cb As String, Optional pStr_Notes As String = "-") Dim dbs As Database Dim lStr_Sql As String Dim numberOfRows Dim lStr_DbName As String Dim llng_Model_Id As Long Dim wrkJet As Workspace Dim SystemDBPath As String Dim AccessEngine As DAO.DBEngine Set AccessEngine = New DAO.DBEngine SystemDBPath = "H:\AccessWrkGrp\master.mdw" AccessEngine.SystemDB = SystemDBPath On Error Resume Next 'Set wrkJet = New DAO.DBEngine '' - - - - - - - - - - - - - - - - - - - - - - - - - - - - ''Create a string holding a full name and path reference to the Access database lStr_DbName = ThisWorkbook.Path & Application.PathSeparator & cStr_DbName If 0 = Len(Dir(lStr_DbName)) Then Exit Sub ''Collects the current model's unique reference llng_Model_Id = gStr_Model ''Test and, if necessary, amend the result If Len(llng_Model_Id) = 0 Then llng_Model_Id = 0 '' - - - - - - - - - - - - - - - - - - - - - - - - - - - - ''Prepare the query ''In the database, column 1 is an AutoNumber field ''So we only insert data into columns 2,3,4 and 5 lStr_Sql = "" lStr_Sql = lStr_Sql & " INSERT INTO DataSource(Model_Id,Datex,Timex,Namex,Notesx)" lStr_Sql = lStr_Sql & " VALUES(" & llng_Model_Id & ",#" & Format(Date, "dd-mmm-yyyy") & "#,#" & Time & "#,'" & pStr_Cb & "','" & pStr_Notes & "')" '' - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'Workspace ' Set wrkJet = CreateWorkspace("", "USERNAME", "PASSWORD", dbUseODBC) ''Open the database ' Set dbs = wrkJet.OpenDatabase(DBName, False, False, "ODBC;UID=USERNAME, PWD=PASSWORD") '************************************************* ********** With dbs ''Execute the query .Execute lStr_Sql ''Close and.. .Close End With ''..tidy up Set dbs = Nothing End Sub Any help would be appreciated. |
All times are GMT +1. The time now is 07:54 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com