Hi I need help in finding the code to open an instance of microsoft access (office 97) with an existing database open, all from within autocad? My file is named .... c:\data\mydatabase.mdb PS I am using ADT2004 Thanks Nigel Downing Design
Private Sub ExportToAccessTable() Dim rs As New ADODB.Recordset Dim rsins As New ADODB.Recordset Dim sSQL As String Dim sINSSQL As String Dim rsretval As RecordStatus Dim i As Integer Dim cn As New ADODB.Connection Dim sConnStr As String Dim dConvert As Double ' -- open database connection On Error Resume Next If LOGIN_PASSWORD <> vbNullString And LOGIN_USERNAME <> vbNullString Then sConnStr = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & txtExportAccess.Text & ";Uid=Admin;Pwd=" & LOGIN_PASSWORD & ";" Else sConnStr = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & txtExportAccess.Text & ";Uid=Admin;Pwd=;" End If frmExport.MousePointer = vbHourglass Do Until cn.State = adStateOpen Or CANCEL_LOGIN = 1 cn.CursorLocation = adUseClient cn.Open sConnStr If Err.Description = "[Microsoft][ODBC Microsoft Access Driver] Not a valid password." Then frmLogin.txtPassword.Text = LOGIN_PASSWORD frmLogin.txtUsername.Text = "Admin" frmLogin.txtUsername.Locked = True frmLogin.Show vbModal, Me Err.Clear sConnStr = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & txtExportAccess.Text & ";Uid=Admin;Pwd=" & LOGIN_PASSWORD & ";" ElseIf Err Then MsgBox Err.Description CANCEL_LOGIN = 1 End If Loop If CANCEL_LOGIN = 1 Then CANCEL_LOGIN = 0 txtExportAccess.Text = vbNullString Exit Sub End If ' #-- insert data -- # sINSSQL = "INSERT INTO " & cboAccessTable.Text & " " Hope that gets you started. Dave
I just want to be able to open up access with an existing file. I dont need to open channels for data between autocad and access. I tried with autolisp (startapp "C:/Program Files/Microsoft Office/Office/MSACCESS.EXE") and got it opening access but couldnt get it to start with the file I want open. Thanks
Just create an object, select it, right-click and choose hyperlink. Browse to the mdb file. Then select it later and right click, hyperlink, open. Dave need to open channels for data between autocad and access. I tried with autolisp (startapp "C:/Program Files/Microsoft Office/Office/MSACCESS.EXE") and got it opening access but couldnt get it to start with the file I want open.
put the following code in a module... it uses API calles to start the appropriate program for a file.. simply pass the filename w/ path to RunProgram_Func and it will handle the rest... example RunProgram_Func "c:\data\mydatabase.mdb" and up will pop your file... ------------------------------------------------------------------- Global DataDirectory As String Global Const strNOTFOUND As String = "NOT FOUND" Global Const iNOTFOUND As Integer = -1 'API Calling Code - General Declarations Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _ lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As _ Long Private Declare Function GetDesktopWindow Lib "user32" () As Long 'ShellExecute Call - RunProgram_Func Private Const SW_SHOWNORMAL = 1 'used by ShellExecute Function RunProgram_Func(tFileToOpen As String) 'uses API calls to load tfiletoopen in the associated program 'note: if tFileToOpen is an URL it will open it 'also: will open "mailto:" 'uses ShellExecute (shell32.dll) Dim Scr_hDC As Long If tFileToOpen = Empty Then ' no file can be loaded Exit Function End If Scr_hDC = GetDesktopWindow() ' RunProgram_Func = ShellExecute(Scr_hDC, "Open", tFileToOpen, "", GetPath_Func(tFileToOpen), SW_SHOWNORMAL) 'If UCase(Right(tFileToOpen, 3)) = "EXE" Then ' Shell "\\lisinc\eks\wineks.exe", vbNormalFocus 'Else RunProgram_Func = ShellExecute(Scr_hDC, "Open", tFileToOpen, "", "", SW_SHOWNORMAL) 'End If Exit Function RunProgram_Err: MsgBox "Error", vbExclamation, "my program" End Function