Code Question (1 Viewer)

JustMaybe

Registered User.
Local time
Today, 00:01
Joined
Oct 18, 2002
Messages
134
okay..i'm not very good at coding....i'm trying to copy some fields in a form to a table.

Can i use the code for forms
e.g.
Private Sub Purchase_Orders_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "PurchaseOrder"
'
DoCmd.OpenForm stDocName, , , stLinkCriteria
'
[Forms]![PurchaseOrder]![EndUser] = [Forms]![Orders]![EndUser]
[Forms]![PurchaseOrder]![OrderID] = [Forms]![Orders]![OrderID]
[Forms]![PurchaseOrder]![MemoField] = [Forms]![Orders]![MemoField]

End Sub

but modify this code using recordsets??

Basically can these bits of code run together in the same algorithm??

Thanks in advance

Sarah
 

crosmill

Registered User.
Local time
Today, 00:01
Joined
Sep 20, 2001
Messages
285
If the fields on the form are linked to the table then the table would be automatically updated from the form.

If you want to code it then (please correct me if I'm wrong) you'll have to use a recordset.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:01
Joined
Feb 19, 2002
Messages
43,484
The problem with the code is that nothing is being set as the criteria, you are passing an empty string.

Private Sub Purchase_Orders_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "PurchaseOrder"
'
stLinkCriteria = "EndUser = " & Me.EndUser & " AND OrderID = " & Me.OrderID
DoCmd.OpenForm stDocName, , , stLinkCriteria
'
End Sub

You should not be storing the same data in multiple places. If it is your intent to copy non-key fields and store them a second time, you need to rethink your design. You should be using queries with joins to obtain related data.
 

JustMaybe

Registered User.
Local time
Today, 00:01
Joined
Oct 18, 2002
Messages
134
You are right....i've decided to use a query!!!

thanks all!!..
 

Users who are viewing this thread

Top Bottom