so simple for an xs programer :: help needed ....switch between forms with data...

  • Thread starter Thread starter Himanshu Mistry
  • Start date Start date
H

Himanshu Mistry

hello all
I want to know that how to switch between two forms in ms access 2000

I have created two forms
Form1 and Form2
there are one button on each
and one text box on each

What I want to do is
I type txtBox1 some msg and press cmdButton1 then
form2 should be displayed.. containing the msg in txtBox2 of form2 ...

and when I press btnButton2 on form2 , I should go back to the form1

I know this is a very simple thing.
But I could not do it...
can anyone help me ...
thanks in advanced...
himanshu
 
dear Jeff
thanks for you reply....
I have already tried the docmd object.
the docmd.openform gives error in name of the form

sending you the code :-------
------------this code is in form1's code window.------------
Private Sub cmdShowFrm2_Click()
Form_temp2.txtCatchMsg = Me.txtMsg.Text

DoCmd.OpenForm Form_temp2
'// it says An expression you entered is the wrong data type for
one of the arguments.
'// and if I do like the following statement
DoCmd.OpenForm "Form_temp2"
' // then it says The form name 'Form_temp2' is misspelled or refers
to a form that doesn't exist.

End Sub

And in the Project Window I actually see the name of both forms as
Form_temp1
Form_temp2

What does the msxs actually want to say regarding this error to me....
please help me.

thanks
himanshu




Jeff Boyce said:
Take a look at the DoCmd.OpenForm command.
--
Good luck

Jeff Boyce
<Access MVP>

hello all
I want to know that how to switch between two forms in ms access 2000

I have created two forms
Form1 and Form2
there are one button on each
and one text box on each

What I want to do is
I type txtBox1 some msg and press cmdButton1 then
form2 should be displayed.. containing the msg in txtBox2 of form2 ...

and when I press btnButton2 on form2 , I should go back to the form1

I know this is a very simple thing.
But I could not do it...
can anyone help me ...
thanks in advanced...
himanshu
 
Himanshu Mistry said:
dear Jeff
thanks for you reply....
I have already tried the docmd object.
the docmd.openform gives error in name of the form

sending you the code :-------
------------this code is in form1's code window.------------
Private Sub cmdShowFrm2_Click()
Form_temp2.txtCatchMsg = Me.txtMsg.Text

DoCmd.OpenForm Form_temp2
'// it says An expression you entered is the wrong data type
for one of the arguments.
'// and if I do like the following statement
DoCmd.OpenForm "Form_temp2"
' // then it says The form name 'Form_temp2' is misspelled or
refers to a form that doesn't exist.

End Sub

And in the Project Window I actually see the name of both forms as
Form_temp1
Form_temp2

What does the msxs actually want to say regarding this error to me....
please help me.

thanks
himanshu

If the names of the forms' *modules*, as displayed in the Project
window, are "Form_temp1" and "Form_Temp2", that implies that the actual
names of the forms themselves, as they would be displayed in the Access
database window, are "temp1" and "temp2". So try

DoCmd.OpenForm "temp2"

instead of what you have.
 
Dear Dirk Goldgar,
Thanks for the help
It works well
But I can't transfer data from one form's control to another form control.
like
I want to set txtForm1 of form1 's text to txtForm2 of form2 's text

------------------------this is the
code --------------------------------------------
Private Sub cmdShowFrm2_Click()

DoCmd.OpenForm "temp2" '// this could open form2

Form_temp2.txtCatchMsg.Text = txtMsgFromForm1.Text
'// here it gives error that you cant assign property till the
control has focus.
'// then I tried to save the text into a globle string variable

sMsgfromForm1 = CStr(txtMsgFromForm1.Text)
'// Then also it gave me the same error :
'// that you cant assign property till the control has focus.
End Sub
 
Himanshu Mistry said:
Dear Dirk Goldgar,
Thanks for the help
It works well
But I can't transfer data from one form's control to another form
control. like
I want to set txtForm1 of form1 's text to txtForm2 of form2 's text

------------------------this is the
code --------------------------------------------
Private Sub cmdShowFrm2_Click()

DoCmd.OpenForm "temp2" '// this could open form2

Form_temp2.txtCatchMsg.Text = txtMsgFromForm1.Text
'// here it gives error that you cant assign property till the
control has focus.
'// then I tried to save the text into a globle string
variable

sMsgfromForm1 = CStr(txtMsgFromForm1.Text)
'// Then also it gave me the same error :
'// that you cant assign property till the control has focus.
End Sub
----------------------------------------------------------------------
------

The main problem with your code attemps is that you are trying to use
the Text property of the text box. Access text boxes are different from
VB and WinForms text boxes in a number of ways. One way is that the
Text property, while it exists, has only very specialized uses and may
only read or set when the control has the focus. Instead, Access text
boxes (and other data controls) use the Value property, which is the
default property and is available at any time.

A second problem, though not a major one, is your use of the form
reference "Form_temp2.txtCatchMsg". This reference to the form's class
module will work, provided that form "temp2" *has* a class module -- not
all Access forms do -- and only one instance of the form is open.
Because it is possible for multiple non-default instances of a form to
be open, this is not the most reliable method of referring to an open
form. The best way is to build your reference through the Forms
collection.

Here is what I would write:

' Assign directly to text box on form "temp2".
Forms!temp2.txtCatchMsg = Me.txtMsgFromForm1


' Assign to global string variable.
sMsgfromForm1 = CStr(Me.txtMsgFromForm1)

Note: since the Value property is the default property, I don't bother
specifying it. Some people insist on this form of the statement:

Forms!temp2.txtCatchMsg.Value = Me.txtMsgFromForm1.Value

It's a matter of personal style. Also, in all probability the CStr()
function is not required in the second assignment. I don't know
everything about your situation and your programming conventions, so I
left it in.

--

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Dirk Goldgar said:
------

The main problem with your code attemps is that you are trying to use
the Text property of the text box. Access text boxes are different from
VB and WinForms text boxes in a number of ways. One way is that the
Text property, while it exists, has only very specialized uses and may
only read or set when the control has the focus. Instead, Access text
boxes (and other data controls) use the Value property, which is the
default property and is available at any time.

A second problem, though not a major one, is your use of the form
reference "Form_temp2.txtCatchMsg". This reference to the form's class
module will work, provided that form "temp2" *has* a class module -- not
all Access forms do -- and only one instance of the form is open.
Because it is possible for multiple non-default instances of a form to
be open, this is not the most reliable method of referring to an open
form. The best way is to build your reference through the Forms
collection.

Here is what I would write:

' Assign directly to text box on form "temp2".
Forms!temp2.txtCatchMsg = Me.txtMsgFromForm1


' Assign to global string variable.
sMsgfromForm1 = CStr(Me.txtMsgFromForm1)

Note: since the Value property is the default property, I don't bother
specifying it. Some people insist on this form of the statement:

Forms!temp2.txtCatchMsg.Value = Me.txtMsgFromForm1.Value

It's a matter of personal style. Also, in all probability the CStr()
function is not required in the second assignment. I don't know
everything about your situation and your programming conventions, so I
left it in.

--

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
-----------------------------------------------------------------------
dear Drik
I run your code into it.
it gives me this error.

Run Time error '2450':

Microsoft Access can't find the form 'temp2' referred to in a macro
expression or Visual Basic code.

Continue End Debug Help

what does it say about the macro expression

Himanshu
 
Himanshu Mistry said:
-
dear Drik
I run your code into it.
it gives me this error.

Run Time error '2450':

Microsoft Access can't find the form 'temp2' referred to in a macro
expression or Visual Basic code.

Continue End Debug Help

what does it say about the macro expression

Himanshu

That means that no form named "temp2" is currently open. I did say the
form has to be open. Did you misspell the form name, or are you trying
to pull data from a form that is not open? If the form is not open,
there is no point opening it just to get data from it -- the proper
thing to do then is to get the data directly from the table or query
that is the form's recordsource, probably using the DLookup function.
Remember that forms don't *contain* data; they are just windows on the
data.
 
Back
Top