Full Version: multiple instances of a form
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
ALMU3YN
Good day & thanks.
i have two student forms:
the name of the first form is frm_student_main .it has a "Add Student" button. and a "Edit Student" button.
the name of the second form is frm_student.
this form opens when the user hits the "Add Student" or "Edit Student" button on the frm_student_main.
the frm_student allows users to enter student name , class, section , and etc ....
a save button saves info to the student_tbl.
a cancel button to exit form without saving.
now let's consider the user keeping the frm_student standby and goes back to frm_student_main and clicks again on one of the two buttons (add or edit student buttons).
this will reload the same frm_student with the new data . data in the frm_student that the user kept standby has been altered with the new ones. Moreover, multiple open instances of frm_student is not possible .Only one frm_student may be open at any one time.
i like to change that so that a user may open multiple instances of frm_student form.
how may i do that? Please.
Doug Steele
See whether what Allen Browne has at Managing Multiple Instances of a Form is enough to get you going.
ALMU3YN

yes,i think this will.
thanks
ALMU3YN

yes,i think this will...thanks...
AQM_UK
If you have form student open modally, it means the user can not navigate away from this form without closing the form some way (cancel / save).

This can be done with seting the form property Modal to yes.

If you sometimes want the form to be modal and other times not then opening the form acDialog is modal and acNormal is not.

This might be something you may find easier.

Jim
ALMU3YN

hello AQM UK.
it's true.
i have seen one SQL-server application that opens multiple instances of the same form.
I like to see that in my Access project.
i read that the .hWnd is not reliable as should be.
i don't know yet whether SQL server has this multiple capability built in.
thanks AQM UK.
AQM_UK
Glad we seem to have helped.

Jim
ALMU3YN

Good_Day_Every_One!
this is the modified code, please comments.

'''the function 'newForm' executes when the button "New Class" of class_main_frm is clicked.
'''''''''''' close one new form ,the other new forms do NOT exit.
Dim classNote As Long
Dim classForm As Form
dim myCollection as New Collection

function newForm()
Dim myform As Form

If IsNull(classNote) Then classNote = 0
classNote = classNote + 1

Set myform = New Form_class_frm
myform.ViewChange = "AcFormView"
myform.Visible = True
'Append it to my collection.
myCollection.Add Item:=myform, Key:="classForm" & CStr(classNote)
Set myform = Nothing
end function
Doug Steele
The line

If IsNull(classNote) Then classNote = 0

is unnecessary. Since classNote is defined as Long, it can never be Null. Variants are the only data type that can be Null. classNote will be initialized as 0.

As far as I know, the line

myform.ViewChange = "AcFormView"

is incorrect. To the best of my knowledge, the Form object does not have a property named ViewChange, and even if it did, "AcFormView" wouldn't be a legitimate value for it. To have the form in a particular view, you'd need to specify the mode as part of the OpenForm command.
ALMU3YN
thanks.gif for all the help.
Time to contemplate options.
Thank you All Very Very Much. Appreciate it.
-o!
ALMU3YN

this is the class module code that i have come up with so far:

Option Compare Database

Dim classNote As Long
Dim curID As Long

Dim classClass As New Collection 'Instances of frmClient.
Function newform()
Dim myform As Form
classNote = classNote + 1
Set myform = New Form_class_frm
myform.Visible = True
''''' myform("notes") references a textbox in class_frm , i use it to call the form back and extract the data from it

myform("notes").Visible = False

myform("notes") = classNote
'Append it to our collection.
classClass.Add Item:=myform, Key:="classForm" & CStr(classNote)
Set myform = Nothing
End Function
Function closeForm(some)

Dim tempForm As Form
Set tempForm = classClass("classForm" & CStr(some))
MsgBox ("notes=" & tempForm("notes")) '''' testing purposes
classClass.Remove ("classForm" & CStr(some))
End Function

Function savedata(abc As String)
Dim v1

v1 = "insert into class_tbl (id_fld,class_fld) values(" & _
Nz(DMax("id_fld", "class_tbl") + 1, 1) & ",'" & abc & "')"
DoCmd.RunSQL (v1)
End Function
ALMU3YN
Kindly comment.
lightbulb.gif

Option Compare Database

Dim classNote As Long
Dim v1, v2
Dim classClass As New Collection 'Instances of class_frm.

Function newform()
Dim myform As Form
classNote = classNote + 1
Set myform = New Form_class_frm
myform.Visible = True
myform("notes").Visible = False
myform("notes") = classNote
'Append it to our collection.
classClass.Add Item:=myform, Key:="classForm" & CStr(classNote)
Set myform = Nothing
End Function

Function closeForm(some)
Dim tempForm As Form
Set tempForm = classClass("classForm" & CStr(some))
MsgBox ("notes=" & tempForm("notes")) ''testing

classClass.Remove ("classForm" & CStr(some)) '' removes the form from colleciton to close

End Function

Function savedata(abc As String)

'''' abc is the value of the notes control in class_frm, i user abc to reference the form
Dim tempForm As Form

Set tempForm = classClass("classForm" & CStr(abc))
v2 = tempForm("class_fld")
v1 = "insert into class_tbl (id_fld,class_fld) values(" & _
Nz(DMax("id_fld", "class_tbl") + 1, 1) & ",'" & v2 & "')"
DoCmd.RunSQL (v1)
End Function
'''''''' uarulez2.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.