how to close form after running code?

L

Lee Rouse

I have set a function to run in the On Current event in a form. I want
the form to close after the code is run. I've tried entering the
Docmd.close command in several different form events, but I either get
errors, or the form remains open.

What code should I use for which event to close the form?

Better yet, is there a way to run the code which is now being fired
via the form's command button, directly from the underlying parameter
query, thereby eliminating the need for the form?

I really don't need the form at all. I'm just using it to trigger the
function.

Thanks,
-leeroi

"knowing just enough about VBA to be dangerous to myself and others"
 
B

Bryan Reich [MSFT]

You can fire a proceedure referenced by name in a string by using the Run
command and passing it the name of the proceedure to fire.
i.e. Run( "MyProceedure" )
or
Dim myproc as String
myproc = "MyProceedure"
Run (myproc)
 
L

Lee

By "myprocedure" do you mean something like "docmd.close"?, and where would
that be inserted in the form events? Sorry for so many question- I'm still
pretty much a struggling newbie with VBA.

Lee

Here's an abbreviated version of the function I'm running, if that's of any
help.

Public Function CreateWordLetter(strDocPath As String)

'if no path is passed to function, exit - no further
'need to do anything

If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If


Dim objWord As Object
Set dbs = CurrentDb

'create reference to Word Object

Set objWord = CreateObject("Word.Application")

'Word Object is created


With objWord
.Visible = True
.Documents.Open (strDocPath)

'move to each bookmark, and insert text.

.activedocument.Bookmarks("FirstLastName1").Select
.Selection.Text = (CStr(Forms![frmmergeIFSP]![Name]))

.activedocument.Bookmarks("FirstLastName").Select
.Selection.Text = (CStr(Forms![frmmergeIFSP]![Name]))

End With
'release all objects

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top