Moving data from Form to form

  • Thread starter Thread starter James
  • Start date Start date
J

James

I have put the code in the before insert property and I
still get this object required. Do we have any idea as to
what this could be?

I have the following code on a button which opens the form
which is :

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSubstanceUse"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
frmAssesment.Visible = False

Then on the before insert on the form (and have tried this
on the actual field) I have the following code:

Me!Ref = Forms!frmAssesment!Ref

Is there anything there that should stop it from working?

Many Thanks

James
 
James said:
I have put the code in the before insert property and I
still get this object required. Do we have any idea as to
what this could be?

I have the following code on a button which opens the form
which is :

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSubstanceUse"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
frmAssesment.Visible = False

Then on the before insert on the form (and have tried this
on the actual field) I have the following code:

Me!Ref = Forms!frmAssesment!Ref

Is there anything there that should stop it from working?

Many Thanks

James

James,

I don't know why you are opening a form to retrieve data from the tables.
You should be doing this with a function. Here's an example of a function
that returns the invoice amount based upon the invoice number.

If you want to give it a try then post the code if you are having problems,
we'll be glad to help you out.

*******************************


Public Function GetInvoiceAmount(TheInvoiceNum As Long) As Currency

Dim strCriteria As String
Dim TheInvoiceAmount As Currency
Dim strSQL As String
Dim dbs As ADODB.Connection
Dim rst As ADODB.Recordset

strSQL = "SELECT * from [tblInvoice] WHERE [Invoice] = " & TheInvoiceNum

' Return reference to current database.
Set dbs = CurrentProject.Connection ' open the database
Set rst = New Recordset ' open a recordset

rst.Open strSQL, dbs, adOpenStatic, adLockReadOnly

TheInvoiceAmount = rst!Invoice_Total

rst.Close
dbs.Close
Set dbs = Nothing
Set rst = Nothing

GetInvoiceAmount = TheInvoiceAmount

End Function
 
Sorry I must not have explained very well...

I need the database to grab the data in the previous form
and add it into the table..

Hope this helps

Many Thanks

James
-----Original Message-----

I have put the code in the before insert property and I
still get this object required. Do we have any idea as to
what this could be?

I have the following code on a button which opens the form
which is :

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSubstanceUse"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
frmAssesment.Visible = False

Then on the before insert on the form (and have tried this
on the actual field) I have the following code:

Me!Ref = Forms!frmAssesment!Ref

Is there anything there that should stop it from working?

Many Thanks

James

James,

I don't know why you are opening a form to retrieve data from the tables.
You should be doing this with a function. Here's an example of a function
that returns the invoice amount based upon the invoice number.

If you want to give it a try then post the code if you are having problems,
we'll be glad to help you out.

*******************************


Public Function GetInvoiceAmount(TheInvoiceNum As Long) As Currency

Dim strCriteria As String
Dim TheInvoiceAmount As Currency
Dim strSQL As String
Dim dbs As ADODB.Connection
Dim rst As ADODB.Recordset

strSQL = "SELECT * from [tblInvoice] WHERE [Invoice] = " & TheInvoiceNum

' Return reference to current database.
Set dbs = CurrentProject.Connection ' open the database
Set rst = New Recordset ' open a recordset

rst.Open strSQL, dbs, adOpenStatic, adLockReadOnly

TheInvoiceAmount = rst!Invoice_Total

rst.Close
dbs.Close
Set dbs = Nothing
Set rst = Nothing

GetInvoiceAmount = TheInvoiceAmount

End Function


.
 
Have you tried putting
=[Forms]![frmAssesment]!Ref
as the defaut value for Ref on frmSubstanceUse?

another way might be to put the following statement:

[Forms]![frmSubstanceUse].Ref= Me.Ref

after the DoCmd.RunCommand acCmdRecordsGoToNew statement in the button.




James said:
Sorry I must not have explained very well...

I need the database to grab the data in the previous form
and add it into the table..

Hope this helps

Many Thanks

James
-----Original Message-----

I have put the code in the before insert property and I
still get this object required. Do we have any idea as to
what this could be?

I have the following code on a button which opens the form
which is :

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSubstanceUse"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
frmAssesment.Visible = False

Then on the before insert on the form (and have tried this
on the actual field) I have the following code:

Me!Ref = Forms!frmAssesment!Ref

Is there anything there that should stop it from working?

Many Thanks

James

James,

I don't know why you are opening a form to retrieve data from the tables.
You should be doing this with a function. Here's an example of a function
that returns the invoice amount based upon the invoice number.

If you want to give it a try then post the code if you are having problems,
we'll be glad to help you out.

*******************************


Public Function GetInvoiceAmount(TheInvoiceNum As Long) As Currency

Dim strCriteria As String
Dim TheInvoiceAmount As Currency
Dim strSQL As String
Dim dbs As ADODB.Connection
Dim rst As ADODB.Recordset

strSQL = "SELECT * from [tblInvoice] WHERE [Invoice] = " & TheInvoiceNum

' Return reference to current database.
Set dbs = CurrentProject.Connection ' open the database
Set rst = New Recordset ' open a recordset

rst.Open strSQL, dbs, adOpenStatic, adLockReadOnly

TheInvoiceAmount = rst!Invoice_Total

rst.Close
dbs.Close
Set dbs = Nothing
Set rst = Nothing

GetInvoiceAmount = TheInvoiceAmount

End Function


.
 
This I have tried and it seems to be working but it does
not seem to insert new records (by this I mean it seems to
overwrite the previos record)...

Would you be kind enough to have a quick glace at the
database as there is only test data in the database...

If so please let me know or if you think there is a simple
solution to the issue that would be great.

Many Thanks

James
-----Original Message-----
Have you tried putting
=[Forms]![frmAssesment]!Ref
as the defaut value for Ref on frmSubstanceUse?

another way might be to put the following statement:

[Forms]![frmSubstanceUse].Ref= Me.Ref

after the DoCmd.RunCommand acCmdRecordsGoToNew statement in the button.




Sorry I must not have explained very well...

I need the database to grab the data in the previous form
and add it into the table..

Hope this helps

Many Thanks

James
-----Original Message-----

I have put the code in the before insert property and I
still get this object required. Do we have any idea
as
to
what this could be?

I have the following code on a button which opens the form
which is :

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSubstanceUse"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
frmAssesment.Visible = False

Then on the before insert on the form (and have tried this
on the actual field) I have the following code:

Me!Ref = Forms!frmAssesment!Ref

Is there anything there that should stop it from working?

Many Thanks

James


James,

I don't know why you are opening a form to retrieve
data
from the tables.
You should be doing this with a function. Here's an example of a function
that returns the invoice amount based upon the invoice number.

If you want to give it a try then post the code if you are having problems,
we'll be glad to help you out.

*******************************


Public Function GetInvoiceAmount(TheInvoiceNum As Long) As Currency

Dim strCriteria As String
Dim TheInvoiceAmount As Currency
Dim strSQL As String
Dim dbs As ADODB.Connection
Dim rst As ADODB.Recordset

strSQL = "SELECT * from [tblInvoice] WHERE [Invoice] = " & TheInvoiceNum

' Return reference to current database.
Set dbs = CurrentProject.Connection ' open the database
Set rst = New Recordset ' open a recordset

rst.Open strSQL, dbs, adOpenStatic, adLockReadOnly

TheInvoiceAmount = rst!Invoice_Total

rst.Close
dbs.Close
Set dbs = Nothing
Set rst = Nothing

GetInvoiceAmount = TheInvoiceAmount

End Function


.


.
 
Sure James. Let me know what version of Access you are using.

Send it to:

(e-mail address removed)


James said:
This I have tried and it seems to be working but it does
not seem to insert new records (by this I mean it seems to
overwrite the previos record)...

Would you be kind enough to have a quick glace at the
database as there is only test data in the database...

If so please let me know or if you think there is a simple
solution to the issue that would be great.

Many Thanks

James
-----Original Message-----
Have you tried putting
=[Forms]![frmAssesment]!Ref
as the defaut value for Ref on frmSubstanceUse?

another way might be to put the following statement:

[Forms]![frmSubstanceUse].Ref= Me.Ref

after the DoCmd.RunCommand acCmdRecordsGoToNew statement in the button.




Sorry I must not have explained very well...

I need the database to grab the data in the previous form
and add it into the table..

Hope this helps

Many Thanks

James
-----Original Message-----

message
I have put the code in the before insert property and I
still get this object required. Do we have any idea as
to
what this could be?

I have the following code on a button which opens the
form
which is :

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSubstanceUse"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.RunCommand acCmdRecordsGoToNew
frmAssesment.Visible = False

Then on the before insert on the form (and have tried
this
on the actual field) I have the following code:

Me!Ref = Forms!frmAssesment!Ref

Is there anything there that should stop it from
working?

Many Thanks

James


James,

I don't know why you are opening a form to retrieve data
from the tables.
You should be doing this with a function. Here's an
example of a function
that returns the invoice amount based upon the invoice
number.

If you want to give it a try then post the code if you
are having problems,
we'll be glad to help you out.

*******************************


Public Function GetInvoiceAmount(TheInvoiceNum As Long)
As Currency

Dim strCriteria As String
Dim TheInvoiceAmount As Currency
Dim strSQL As String
Dim dbs As ADODB.Connection
Dim rst As ADODB.Recordset

strSQL = "SELECT * from [tblInvoice] WHERE [Invoice]
= " & TheInvoiceNum

' Return reference to current database.
Set dbs = CurrentProject.Connection ' open the
database
Set rst = New Recordset ' open a recordset

rst.Open strSQL, dbs, adOpenStatic, adLockReadOnly

TheInvoiceAmount = rst!Invoice_Total

rst.Close
dbs.Close
Set dbs = Nothing
Set rst = Nothing

GetInvoiceAmount = TheInvoiceAmount

End Function


.


.
 
Back
Top