Open Access 2003 or 2007 from Excel
Here is some current code:
Sub OpenAccess()
'THIS WORKS; IT ALSO REQURES THE SUB "SHOWACCESS" AND ASSOCIATED
'OPTION EXPLICIT FUNCTION AND CONST STATEMENTS AT TOP OF MODULE
Set objAccess = GetObject("c:\UOEnglish.mdb")
ShowAccess objAccess, SW_MAXIMIZE
'EXAMPLE OF USING WITH TO EXECUTE COMMANDS
'With objAccess
'.AutoCenter = True 'doesn't work...need to define form acts on?
'.Visible = True 'makes it visible
'.DoCmd.RunMacro "mcrImportCourses" 'runs this macro
' Print the Product Catalog report.
'.DoCmd.OpenReport "Catalog", acViewNormal, , _
' "CategoryName = '" & strCategoryName & "'"
'End With
'EXAMPLE OF ACCESS COMMAND TO CONTROL FORMS
'Forms!Customers.Visible = True
'objAccess.DoCmd.AutoCenter = True 'doesn't work
'objAccess.DoCmd.Forms!Switchboard.AutoCenter = True 'did not work
'EXECUTING COMMANDS WITH THE OBJECT ATTACHED TO EACH COMMAND
'objAccess.DoCmd.RunMacro "mcrImportCourses"
'objAccess.Quit 'closes Access
'Set objAccess = Nothing
End Sub
Private Sub UpdateAccessUDR()
'Having problems with this...need to debug
'To add named variables to records table in Access database
'
'Dim dbMain As ADODB.Connection
Dim AccTable 'The variable for Access Table for the records to be added to
'Dim dbMain As ADODB.Connection 'compile error: user-defined type not defined
Dim strSQL As String 'define SQL string
Dim EnrlCur, UDR 'variables for those values
Dim UDRColNum 'column number for the UDR data
Dim i As Integer
Dim TotRecNum As Integer
Sheets("Main Data").Select
FilenameTest = "UOEnglish.mdb"
DocPath = "c:\"
FnameTemp = DocPath & FilenameTest
AccTable = "tblCourses"
Dim dbMain As Object 'this seemed to be accepted
Set dbMain = CreateObject("ADODB.Connection")
'Dim rsRecordset As ADODB.Recordset 'this suggested fix didn't work
'open connection
'METHOD USING FnameTemp FOR FILENAME...should work
dbMain.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & FnameTemp & ";Persist Security Info=False"
'selects all records from table defined by AccTable variable
' check on method to select specific records that match fields with AND/OR
strSQL = "SELECT * FROM " & AccTable
'declare, set, open recordset, using above strSQL select command
' to get records from AccTable
Set rsRecordset = New ADODB.Recordset 'didn't like this...error
rsRecordset.Open strSQL, dbMain, adOpenDynamic, adLockOptimistic
'check for empty recordset
If rsRecordset.BOF And rsRecordset.EOF Then
'MsgBox "Recordset is empty!"
GoTo AddNewRecord
'Exit Sub
End If
"Donna" wrote:
I have an application created in Excel that at certain points opens a
database named "engl.mdb". All worked fine for years until some of us got
new computers that now have VISTA as the OS. The database path is
c:\engl.mdb on the XP machines, but it can't be stored directly on the root
of C in Vista because Vista has some sort of security thing going on that
will only allow it to be opened in a READ-ONLY format. (I have searched for
days on how to change this but get nowhere.) So now we need to store the
database on the Vista machines in the following path --
c:\UserName\Engl\engl.mdb -- but on the XP machines the path is c:\engl.mdb
Is there code that can be substitued in the current Excel VBA code that can
call (Open) the database in either Vista or XP using the different path names?
|