Set frmMain = db.Containers("Forms").Documents("Main") doesn't open a form.
You need to explicity open the form, then set a reference to the form you
just opened. I haven't tested, but I believe you're going to need to use
Automation to do this
Sub UpdateCounty(County As String)
Dim objAccess As Access.Application
Dim frmMain As Form
Set objAccess = New Access.Application
With objAccess
.OpenCurrentDatabase County
.DoCmd.OpenForm FormName := "Main"
Set frmMain = .Forms("Main")
End With
' more code
With objAccess
.DoCmd.Close acForm, "Main", acSaveNo
.CloseCurrentDatabase
End With
Set objAccess = Nothing
End Sub
To learn more about using Automation with Access, check out:
ACC: Using Microsoft Access as an Automation Server
http://support.microsoft.com/?id=147816
ACC2000: Using Microsoft Access as an Automation Server
http://support.microsoft.com/?id=210111
--
Doug Steele, Microsoft Access MVP
JonWayn said:
I cannot use any of the methods you suggested because the form I am
interested in is in a closed remote database. Therefore Forms("Main") or
Forms!Main will not work.
You need: set frm = Forms("Main")
or: set frm = Forms![Main]
The Forms *collection* (used above) is the collection of all >open< forms.
The forms *container* (used in your code) is a container of documents,
each
of which is a form >defined in< your database (but not necessarily open).
Also, you are well advised to say DBEngine.OpenDatabase(...), not just
OpenDatabase(...). This avoids some DAO licencing errors that can
occur
on
some PCs.
HTH,
TC
I keep getting "Type mismatch" error when I try the above.
Sub UpdateCounty(County As String)
Dim db As Database, frmMain As Form, mdl As Module, cont As Object
Dim x%
Set db = OpenDatabase(County)
Set frmMain = db.Containers("Forms").Documents("Main")
'more codes
End Sub
I have tried several other ways using that containers and Documents
collection but these dont seem to lead to a path to the actual forms
contained in the database. Is there any suggestion out there on