VBA in Word Opens Access Object/Form How to get Values Back?

M

Michael

I have VBA behind a Word Doc - all variables are dimensioned above.



Const DB_PATH As String = "F:\ClientDocs\Programs\SaveFile.mdb"
Path = "F:\ClientDocs\ClientDocuments"

OpenArgs = DocName
If Nz(ClientId, "") <> "" Then
OpenArgs = OpenArgs & ";" & ClientId & ";" & CStr(TheYear)
End If

On Error GoTo Err_Get_Client_Classify_Path

Set acApp = New Access.Application
With acApp
.OpenCurrentDatabase DB_PATH
.Visible = True

OldObs = .Forms.Count

.DoCmd.OpenForm "frmDocuments_Single", , , , , , OpenArgs

' pause while form open

Do

DoEvents

NewObs = .Forms.Count

If NewObs <> OldObs Then
' form is open but may get here again after the form is
actually just closed!
***
*** statements like the following "worked" but needed error shielding
because they executed once after the form was closed
*** ClientID = forms!frmDocuments_Single!Fld_code
*** but then, the rest of the program was "upset" and caused the Nz failure
mentioned below.
***
Else
' form is closed
Exit Do
End If
Loop
' end of pause loop

ClientId = m_strClient_ID ' next 3 don't work
TheYear = CInt(m_strYear)
DocName = m_strDocName

End With

acApp.Quit
Set acApp = Nothing


The called form has several controls and does other things. If it is called
without passing the Client_ID and TheYear, I want the values entered in the
form, returned to the calling program.

I have discovered that Global xxx does not apply when an Access object is
opened up as above.

Does anybody know of a way (apart from writing to somewhere and reading
after) to pass bak values?

See *** block
I was able to get values from the open form but these eventually caused the
program to get itself mixed up - causing subsequent function calls e.g. x =
nz(y,"") to fail with bizarre messages.

TIA
Michael
 

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

Similar Threads


Top