Hi
Sorry I didn't see your reply until today
Let me just quickly explain how to use Access as a server
You first dimension a variable that's going to hold the reference to MS Access (Think of it as an alias or nickname for MS Access if you must)
I this case any name can be used [It's best to keep it as descriptive as possible]
Dim objAccess As Access.Application
Now If you didn't set a reference to Access then your intellisense would not pick up Access.Application to complete the words
What you have to do is Select
Project->
References and search for Microsoft Access <version> Object Library.
<I have version 8.0.>
Okay so we've dimensioned the variable of type Access, now we need to activate it (since you
aufait with DDE you can think of this as activating the conversation (DDEInitiate)
To activate the link
Set objAccess = GetObject(,"Access.Application"
This will return an error if Access is not running
If you really want to comunicate with an active Access session then use GetObject.
If you just want to do some stuff to Access that does not require an active session then use CreateObject
The syntax for CreateObject is similar
CreateObject("Access.Application"
CreateObject will always create a new session of Access. So as with DDE you need to have the Application running so is it with COM. The difference with using COM is that you have more power with the Application
Okay at this point I'll provide the code because if you're not confused by now then you must be familiar with COM.
Code:
Option Explicit
Private m_objAccess As Access.Application
Private Sub Form_Load()
Const sMDBFile As String = "d:\db1.mdb"
Dim bTryAgain As Boolean
Dim sCondition As String
Dim sFormName As String
On Error GoTo ErrorHandler
bTryAgain = True
sCondition = "Surname = " & Quote("HENNINGS")
sFormName = "MyForm"
Set m_objAccess = GetObject(, "Access.Application")
If Not m_objAccess Is Nothing Then
With m_objAccess
.OpenCurrentDatabase sMDBFile
DoCmd.OpenForm sFormName, _
acNormal, , sCondition, , _
acDialog
End With
End If
Exit Sub
ErrorHandler:
If Err.Number = 429 Then
If bTryAgain Then
bTryAgain = False
If m_objAccess Is Nothing Then
Set m_objAccess = CreateObject( _
"Access.Application" _
)
Resume 'Try using GetObject again
End If
End If
End If
MsgBox Err.Description, , Err.Number
End Sub
Private Sub Form_QueryUnload( _
Cancel As Integer, UnloadMode As Integer _
)
If Not m_objAccess Is Nothing Then
m_objAccess.Quit
Set m_objAccess = Nothing
End If
End Sub
Private Function Quote(sString As String) As String
Quote = Chr(34) & sString & Chr(34)
End Function
Don't feel daunted by the amount of code (I always tend to get out of hand) It's the Error Handling that takes up so much space.
The code could easily have been...
Code:
Dim x As New Access.Application
x.DoCmd.OpenForm "Section38 Current", acNormal, "", "[Section38 Current]![Road Name Rd1]=""Oberon Road""", , acNormal
But I hate sloppy code #-)
Have fun
caf