Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open New record in another Form 2

Status
Not open for further replies.

desikan

Technical User
Feb 2, 2001
105
AE
I have a continous form say Form1 (read only) with fields "field1","field2","field3". I have a command button in the form which opens up another form say Form2 with a new record containing the same fields.

Now I want field1 which is chosen in Form1 to be displayed in Form2 in the relevant field. I am using presently a combo box in Form2 to get the field but what I need is the "field1" to be displayed directly in a a text box or combo box when Form2 is opened.

I have gone through severaol old posts but I cannot get any clues. Any help will be appreciated.

Thanks.
 
Hi desikan,
The way I would go about this would be by using the openargs argument when opening form 2.

so basically, the way to go about this would be the following.

In the openform method you are using when the user clicks the command button to open form2, the last argument (openargs) should be the value of field1. The in the "open" event of form2 use field1textbox.value = me.openargs.

This will set the value of field1textbox to the value which was passed when the command button was pressed.

hope this helps, let me know.
 
Hi, Thanks for your reply but I am unable to figure out the exact expression to be written.

Can you please help me out?

Many thanks
 
Lets assume I have 2 forms, Form1 and Form2. On Form1 I have a textbox name TXTField1, this contains the Field1 you were talking about, the one you want to display on Form2. Also on Form1 I have a Command button named COMOpen. Below is the code I would place in the command button:

docmd.OpenForm "Form2", acNormal,,,acFormEdit,acWindowNormal, txtfield1.value

On form2 you have a textbox which is name TXTField1 as well, in the "open" event of Form2 you place the following code:

txtfield1.value = me.openargs

This will cause the textbox on form2 to have the value of the textbox on form1, which was linked to the Field1 you wanted to display on form2.

Let me know how it works.
 
Well I put the code you suggested but I am getting syntax error message in the code for the command button when I click the command button.

Can you please check?
Thanks a lot

 
what is the error you are receiving? The statement looks fine to me. Remember, you'll have to change the names of the stuff I posted to the names of your stuff. If you want things to work properly.

Thanks,
James
 
My code in the command button in Form1 is DoCmd.OpenForm "Form2", acNormal, , , acFormEdit, acWindowNormal, [type].Value

Ny code in Form2 is

Private Sub Form_Open(Cancel As Integer)
[type].Value = Me.OpenArgs
End Sub

I am getting the error as "You can't assign value to this object" and the program stops at the code in Form2.

And thanks a lot for spending so much time patiently on my problem


 
hmmm... is the name of your textbox on form2 type? If so I'd change it to something like txttype on both forms. you shouldn't need square brackets around the control name either. So change both controls names (the one on Form1 and the one on Form2) to TXTType, and then edit your code accordingly. (switch [type].value with TXTType.value) that should work.

James
 
Well I changed the name of the field as TXTType and retyped the code as you had suggested but still I am getting the same error message viz
"You can't assign value to this object" and the program stops at the code in Form2.



 
if you have access 2000 or earlier you could zip then email your DB to jtseleie@theedge.ca, I could then fix it and return it to you.
 
Hi, I have mailed my db to your address

Thanks a lot
 
Hi desikan,
My bad, you can't change the .value property of a bound control. On FORM2 in your project, change the code from

CARD.value = me.openargs

to

Card.setfocus
card.text = me.openargs


That will fix your problem. Just remember that you always have to set focus to a textbox before using the .text property. And you can only set the .value property of an unbound txtbox.

James
 
Well I am finding short of words to thank you really. I put your modification and it worked like a song.

To make Form2 open with a new record (so that every fault will be recorded on a new record) I added Docmd Newrecord line before card.setfocus line and everything worked beautifully.

To make my understanding clear, I have a small query though. Why do we put code in the command button as card.value though the value was picked from a bound control in Form1 where as in Form2 you have explained that we must use card.text ?

And I have learnt a great deal today about complicated expressions from you and I am sincerely grateful for that.

 
Thanks desikan, helping is no problem,
The .value property of a textbox can be read from anywhere in code. The thing is, the .value property of a textbox doesn't change until the textbox loses focus. THe .text property of a textbox changes as the text in the box changes. But in Access, you need to have focus set on the textbox in order to access the .text property. Thats why I normally use .value. This is where another problem arises, you can't write the .value property of a bound textbox control, only read it. That was the reason we needed to use the .text property of the control in order to get what you wanted to do to work.
 
Hey,

I have the same kind of problem, only my I can also open "old" records with the button. So there is already a value (stLinkCriteria) connected to the button:


Private Sub Name_Form_Click()
On Error GoTo Err_Name_Form_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Name"

stLinkCriteria = "[Name]=" & "'" & Me![Name] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Name_Form_Click:
Exit Sub

Err_Name_Form_Click:
MsgBox Err.Description
Resume Exit_Name_Form_Click

End Sub

I need this one to open the right record, but if I open a new record then I cant save the info. Because the related record is still "0" (Its related to a auto ID)

I hope someone can help me!!

Xiphiaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top