Open an Access Form based on a class

G

Guest

Hi,
I've got two forms (search and detail). Each form has an own class (events:
showing, saving etc.). The idea is to use a search form, having an output
(ID, Name etc.) I'd like to open the detail form using an ID from the search
form to show all record details. But how to pass to the detail form the
ID-parameter?
My detail form has a property ID, I want to set this property using the ID
value from the search form. But I can only use docmd.openform("xxx") and
there is no chace to pass the ID as a paramater. I don't want to use
something like that: docmd.openform("vv").recordsource = ID or something like
that. Is this possible?
Thanks for your help
 
G

George Nicholson

Lots of ways to skin this cat.

1)
My detail form has a property ID
(from the Search form)
DoCmd.OpenForm "vv"
Do Until IsLoaded("vv")
DoEvents
Loop
Forms("vv").ID =Me.ID

(IsLoaded is a basic user-defined function available in Northwind and
elsewhere.)

Keep in mind that at this point the Form is already open, so the Open or
Load events have already fired. You'd need to find another way to "tell"
the form that it needs to do something with the information it just
received. Let_ID could easily provide that functionality.

Overall, this approach is probably more trouble than its worth considering
the other available methods..

2)
Per Online VBA Help:
DoCmd.OpenForm(FormName, View, FilterName, WhereCondition, DataMode,
WindowMode, OpenArgs)

-You can use either the WhereCondition or the OpenArgs arguments of OpenForm
to pass information directly to the Detail form.
DoCmd.OpenForm "vv",,, "ID = " & Me.ID
DoCmd.OpenForm "vv",,,,,, Me.ID

3)
-in the Open event of the Detail form, you can retrieve & react to the ID
value of the Search form (assuming its still open).

4)
-You could have your Search form set a global variable with the ID value and
then use the Open event of the Detail form to retrieve & react to that
value.



HTH,
 
G

Guest

' In a module
Public Function IsOpen(strForm As String) As Boolean
IsOpen = (SysCmd(acSysCmdGetObjectState, acForm, strForm) > 0)
End Function

' In frm_search
Private frm_detail As Form_frm_detail

If IsOpen("frm_detail") And Not frm_detail Is Nothing Then
frm_detail.CallingName = strSearchString
Else
DoCmd.OpenForm "frm_detail", _
DataMode:=acFormEdit, _
WindowMode:=acWindowNormal, _
OpenArgs:=Trim(CStr(lngExcursionID)) & "^" & strSearchString &
"^" & Me.Name
Set frm_detail = Application.Forms("frm_detail")
End If

' ****In frm_detail*****

Private ParentForm As Form
Private ParentFormName As Variant

Property Set ParentObject(fValue As Form)
Set ParentForm = fValue
ParentFormName = ParentForm.Name
End Property

Property Let CallingName(vValue As Variant)
Me!dspSearchPhrase.Value = CStr(vValue)
End Property

Private Sub Form_Load()
Dim lngOne As Long
Dim vTargetKey As Variant
Dim vCallingForm As Variant
Dim vInstanceID As Variant

If Not IsNull(Me.OpenArgs) Then

lngOne = 1
vInstanceID = Trim(Nz(Left(Me.OpenArgs, InStr(lngOne, Me.OpenArgs,
"^") - 1), ""))
lngOne = InStr(lngOne, Me.OpenArgs, "^") + 1
vTargetKey = Trim(Nz(Mid(Me.OpenArgs, lngOne, InStr(lngOne,
Me.OpenArgs, "^") - lngOne),

""))
lngOne = InStr(lngOne, Me.OpenArgs, "^")
vCallingForm = Trim(Nz(Right(Me.OpenArgs, Len(Me.OpenArgs) -
lngOne), ""))
Set ParentObject = Application.Forms(vCallingForm)
lngExcursionID = CLng(Nz(vInstanceID, "0"))
CallingName = vTargetKey ' A method to initialize the form

End If ' If Not IsNull(Me.OpenArgs) Then
 

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