Writing Data with unbound controls

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

Guest

I have a form (test form) that has 2 subforms on it(test form - prod form)
with many unbound controls that are doing calculations. On one of the sub
forms I need to write data from the unbound control (that is doing a
calculation) to a table called (prod table)
This code is used by a button - on click-Here is the code I have -


Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("prod table")

rs.AddNew
rs!FormulationCost = Forms!prod form!FormulationCost
rs.Update
rs.Close


I get a run-time error 2450 - Can not find the form Prod Form in the macro
or vb.
Do you have to add something if you are using a sub form (prod form being
the sub form on my test form?

Many thanks in advance.
Curt
 
When a name of a form, or a field is consist of two words you need to put it
in square brackets

Forms![prod form]!FormulationCost
 
One more thing, if you want to get a value from a sub form

Forms![MainFormName]![Sub form control name].Form![FieldName]
 
Thanks Ofer for your reply, but I tried your values and now I am still
getting an error that it can not find the form: Here is my code below and let
me give you exact detail. i have a table called productioncost - I have a
form called test recipe which has the sub form called productioncost. I want
to take the value of my unbound caluculated field (formulacost) located on my
subform productioncost and write to my productioncost table
(formulacalculation)Here is the code and i am still getting that can find
productioncost form???

Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("productioncost")
rs.AddNew
rs!FormulationCost = Forms![Test recipe]![Sub form
Productioncost].Form![FormulationCost]



rs.Update
rs.Close

Ofer said:
One more thing, if you want to get a value from a sub form

Forms![MainFormName]![Sub form control name].Form![FieldName]

--
I hope that helped
Good luck


Curt Johnson said:
I have a form (test form) that has 2 subforms on it(test form - prod form)
with many unbound controls that are doing calculations. On one of the sub
forms I need to write data from the unbound control (that is doing a
calculation) to a table called (prod table)
This code is used by a button - on click-Here is the code I have -


Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("prod table")

rs.AddNew
rs!FormulationCost = Forms!prod form!FormulationCost
rs.Update
rs.Close


I get a run-time error 2450 - Can not find the form Prod Form in the macro
or vb.
Do you have to add something if you are using a sub form (prod form being
the sub form on my test form?

Many thanks in advance.
Curt
 
Try this

rs!FormulationCost = Forms![Test recipe]![productioncost].Form![formulacost]
Also, it is not recomded saving a calculated field in a table, it mean that
you have to keep maintaining it, and if somone will update the table this
field wont be updated
You can always retreive the value using a query

Select Field1, field2, field1 * field2 as Field3 From TableName


--
I hope that helped
Good luck


Curt Johnson said:
Thanks Ofer for your reply, but I tried your values and now I am still
getting an error that it can not find the form: Here is my code below and let
me give you exact detail. i have a table called productioncost - I have a
form called test recipe which has the sub form called productioncost. I want
to take the value of my unbound caluculated field (formulacost) located on my
subform productioncost and write to my productioncost table
(formulacalculation)Here is the code and i am still getting that can find
productioncost form???

Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("productioncost")
rs.AddNew
rs!FormulationCost = Forms![Test recipe]![Sub form
Productioncost].Form![FormulationCost]



rs.Update
rs.Close

Ofer said:
One more thing, if you want to get a value from a sub form

Forms![MainFormName]![Sub form control name].Form![FieldName]

--
I hope that helped
Good luck


Curt Johnson said:
I have a form (test form) that has 2 subforms on it(test form - prod form)
with many unbound controls that are doing calculations. On one of the sub
forms I need to write data from the unbound control (that is doing a
calculation) to a table called (prod table)
This code is used by a button - on click-Here is the code I have -


Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("prod table")

rs.AddNew
rs!FormulationCost = Forms!prod form!FormulationCost
rs.Update
rs.Close


I get a run-time error 2450 - Can not find the form Prod Form in the macro
or vb.
Do you have to add something if you are using a sub form (prod form being
the sub form on my test form?

Many thanks in advance.
Curt
 
Back
Top