Update form2 by a click of a button in form1

varunvithalani

Registered User.
Local time
Today, 17:37
Joined
May 11, 2010
Messages
19
Hello,

I have 2 forms. Let me call them form1 and form2. Both these forms have their tables as data sources.
What I wish to do is: By pressing a button in form1, I want to copy the contents of the previous record in form2 to the next record in form2.

Currently, when I tried this I am unable to access the previous records of form2 at all. (not even from form2 itself). Does it have something to do with the Primary key that the record pointer does not move to the previous one.
I have an autonumber as a pk in form2's table.

Kindly suggest me a solution if possible. Thank you.
 
I think basically you might need to show some code.

I have 2 forms. Let me call them form1 and form2. Both these forms have their tables as data sources.
One comment to be helpful (but has nothing to do with your question) is that making a form's record source equal to a table is usually a waste of resources. It is like going to McDonalds and buying a BigMac Menu with fries and cola - just cause you are thirsty and need a drink and you throw away the burger and fries.

You should try to limit these forms to just the information you need.
 
Hello,

Let me try and paint a better picture,

Form1 has one button 'btnCopy'
Form2 has 2 fields 'Field1' and 'Field2'
Now, By the press of 'btnCopy' in form1, 'Field1' and 'Field2' of form2 from the current Record must be copied to the next record in form2 itself.

This is just a gist of the entire story. I just want to understand the concept behind it and then I can do it myself. The problem I currently face is that any code in form1 is not able to access form2(providing cannot find errors), i am guessing since it has no focus and form1 is the active one.

This is something my boss has asked me to do for the database for his own comfort. I cant have an alternative but have to follow his instructions.

Hope you can help.
Thanks.
 
Two things I can think of.

1. If your Forms are on the Table then you can Add/Append Records but.. Not the primary Key. This will be created by the table.
Just check you are not copying the primary from one record onto another which of course can not happen as they must be unique.

2. When referencing Controls on a form (fields in a query/table) you use different addresses for when the controls are on a mainform or a subform.

I will try and find the link to a "Cheat Sheet" on this issue.
 
This might get you started

save the two field values to a variable

Code:
str_Field1 = Forms("Form2").Field1.value
str_Field2 = Forms("Form2").Field2.value

'you might need to set focus on the form eg
'Forms("Form2").Setfocus

DoCmd.GoToRecord , , acNewRec

Forms("Form2").Field1.value = str_Field1
Forms("Form2").Field2.value = str_Field2
 
Hello,

Thank you so much with your last post.
I realized i messed up the syntax.
But when I press Forms("Form_name").______
it should give me suggestions for fields right? The only options i get are of the forms properties.

Thanks, Kindly reply.
 
Last edited:
No it wouldn't give you a drop-down of names of fields related to that form because you're dealing with the Forms collection. It would show you generalised properties/methods.
 
Hello,

So I should put the name of the control after the form name or I should put the name of its relavant Field?

Thanks
 
Hello,

It keeps telling me, Cant find the form, even when I put the form name as correct.

Thanks. Kindly help
 

Users who are viewing this thread

Back
Top Bottom