how to take a value from one form to anothor

sspreyer

Registered User.
Local time
Today, 09:59
Joined
Nov 18, 2013
Messages
251
hi

all

right I have form called frmplant on open I select plant type from the combo box then there is a sub form called plantitem tbl subform this show's the plant under that type on a continuous form so the user enters the plant information then they have command button to open another form call frmpopupPlantService to log the service history of the plant item the user enters the service date and service notes I have text box call "add" this shows the next service due this is the value I want to add to plantitem tbl subform in the service due date box when frmpopupPlantService form is closed

this what I have tried
Code:
 Me.add = [Forms]![frmplant]![PlantItemTbl subform]![ServiceDueDate]
 [Forms]![frmplant].Requery

but I get error
run time error
you can't assign this value to a object

here a sample of my database hope this helps

View attachment shanetest.zip

thank in advance

shane
 
hi
vbaInet

yes that is how i open frmpopupPlantService I want update values on
plantitem tbl subform from frmpopupPlantService when form is closed

cheers

shane
 
Oh alright. Before the form closes pass the value to the textbox like this:
Code:
Forms![COLOR="blue"]FormName[/COLOR]![Add] = Me.[COLOR="blue"]ControlName[/COLOR]
You'll be passing directly from the form that's about to close. So put it in the Unload event.
 
right I have tried

Code:
Forms!FormName![add] = [Forms]![PlantItemTbl subform]![ServiceDueDate]

I get error can't find reference run time error 2450
to plantitemtbl subform

thanks

shane
 
Please use the exact syntax as I gave you. Put that code in the Unload event of the subform.

By the way Add is a reserved keyword in Access. You should avoid using those sort of words because it could lead to unnecessary irregularities. Here's a comprehensive list:
http://allenbrowne.com/AppIssueBadWord.html
 
right

done as you said now I get compile error method or data member not found

little more info

I have changed "add to "datedue" this is a calculated field it generates its value by taking a value from a text box call months e.g if 12months it will see the service date and add 12months for e.g 20/01/14 + 12months 20/01/15<--this is the value I want to enter on the other form on when it close in servicedatedue text box

thanks again sorry for being pain

shane
 
no just the record that the user opens form by clicking the command button add service

cheers

shane
 
So how far did you get with the link I sent you? It explains how you would reference controls depending on which form or subform you're in.
 
hi

right I have tried the link you supplied

still can't get it to work I wonder if there a easier way

take the value from

service date text box which is bound from the plantservice sub form then

do this calutation

DateAdd("m",[Forms]![frmplant]![PlantItemTbl subform]![months],[servicedate])


then add it to service date due text box on plantitemtbl sub form

to be honest mate I am very very lost

thanks for the help

shane
 
Ok, let me see the full code. And I would like to know where you put the code, which form's event?

It can do any calculation you want it to. Let's get the referencing right first.
 
mate I wouldnt know were to start my vba knowledge is little to done

normally stick to macros

thanks for help tho

shane
 
I asked to see the code that you wrote following my advise from previous threads. If I can't see your code I can't spot your mistake. And I would like to know where you put the code too.
 
hi

right I have put this code

in my PlantServiceTbl subform on unload event to update my PlantItemTbl subform service due text box

Code:
Me.Datedue = [Forms]![frmplant]![Plantitemtbl subform] = ServiceDueDate
still with no success :banghead::banghead::banghead:

I have sample to show what going on

View attachment shanetest2.zip


cheers

shane
 
VBA doesn't assign like that. Think of it this way. The left hand side of the equal to sign (=) is where you want your value to go. The right hand side is where the value is coming from. So remember, left for receiver and right for sender. Makes sense? You can't have two receivers or two senders on one line of code.

Secondly, if you're in a form the "Me." reference means the form you're currenly on so it will only work for those fields or controls in that form.

Answer these questions and I'll write it up:
1. What is the name of the form the Service due field is in?
2. Is the Service Due field in a subform? If so, what is the name as well?
3. Is Service Due the receiver?
 
Hi

The servicedatedue is on a subform called "plantitemtbl subform "its main form is called "frmplant"

It is the receiver


Thanks

Shane
 
Code:
Forms![frmplant]![Plantitemtbl subform]!ServiceDueDate = Me.DateDue
It needs to go in the Unload event of the form where DateDue is in. And when I mean Unload event I don't mean you should just paste that code in the Unload event box, you need to click the button next to it, select Code Builder, hit Ok and paste the code there.
 

Users who are viewing this thread

Back
Top Bottom