A fleeting instance of a Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm trying to open an instance of a calendar form on clicking on the "Date
Out" button of an equipment loans form. The code I have used is as per
below. However, on clicking the Date Out button, the calendar form opens but
then immediately closes again. I imagine I'm doing something blindingly
obviously wrong but would very much appreciate help on this.

Thanks

Private Sub cmdDateOutEdit_Click()

Dim calendar1 As Form_frmCalendar
Set calendar1 = New Form_frmCalendar
calendar1.Visible = True

End Sub
 
Yes...your form goes out of scope once the routine is executed. You need to
either open the form using DoCmd.OpenForm or modify your code to poll for an
event that occurs within frmCalendar.
 
I tried using the command DoCmd.OpenForm "calendar1" as suggested but
received the error message: "The form name 'calendar1' is misspelled or
refers to a form that doesn't exist"

Private Sub cmdDateOutEdit_Click()

Dim calendar1 As Form_frmCalendar
Set calendar1 = New Form_frmCalendar

DoCmd.OpenForm "calendar1"

End Sub
 
I tried using the command DoCmd.OpenForm "calendar1" as suggested but
received the error message: "The form name 'calendar1' is misspelled or
refers to a form that doesn't exist"

Well? Do you have a Form named calendar1 in the Forms window?

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Italian Pete said:
I tried using the command DoCmd.OpenForm "calendar1" as suggested but
received the error message: "The form name 'calendar1' is misspelled
or refers to a form that doesn't exist"

Private Sub cmdDateOutEdit_Click()

Dim calendar1 As Form_frmCalendar
Set calendar1 = New Form_frmCalendar

DoCmd.OpenForm "calendar1"

End Sub

It appears to me that you should simply have written this:

Private Sub cmdDateOutEdit_Click()

DoCmd.OpenForm "frmCalendar"

End Sub
 
John, I don't have a form named "calendar1" in the Form window. I have a
form named "Form_frmCalendar". calendar1 is an instance of Form_frmCalendar,
or at least this is my intention. I want to create a different instance of
Form_frmCalendar depending on the type of date to be input (there are 4 types
of date: 1)date equipment is booked 2) date equipment is due back 3) date
equipment returns and 4) date equipment goes out)

:
 
Dirk, I can open the form as you suggest, but I want to create an instance of
it and open that.
 
Italian Pete said:
Dirk, I can open the form as you suggest, but I want to create an
instance of it and open that.

Do you mean that you want to create one of several possible concurrent
instances of the form? Then you must use a mechanism to keep a
persistent reference to the instance. This reference must survive for
the length of time you want to work with the form. There are a number
of ways to do that, but I don't want to recommend one until I'm sure I
understand how you want to use these instances.

Do you really want to have multiple instances of this form open at the
same time, or do you want to open the form, wait until the user chooses
a date and clicks some button or other, and then get the date from the
form? From your other messages, I get the impression that latter
procedure is what you have in mind.
 
John, I don't have a form named "calendar1" in the Form window. I have a
form named "Form_frmCalendar". calendar1 is an instance of Form_frmCalendar,
or at least this is my intention. I want to create a different instance of
Form_frmCalendar depending on the type of date to be input (there are 4 types
of date: 1)date equipment is booked 2) date equipment is due back 3) date
equipment returns and 4) date equipment goes out)

The argument to the OpenForm method is the name of a Form in the
Documents collection - not the name of an instance. I'll defer to
Dirk, he's got a lot more experience than I do in this area!

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top