Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Create New Order Record From Old Record
Colin M 

11 years ago
All of the fields copy over the correct information, except for the very first field. I am trying to copy the previous record's InvoiceNumber into a different field on the new record called "PreviousInvoice#". Nothing gets copied over for this particular field and there is no error message. Here is the Macro code that I am using. The line that doesn't work is this line:

PreviousInvoiceNo = DLookup("InvoiceNumber", "TestOrderQ", "OrderID=" & ID)

Can anyone tell me why this is not working, and how to fix? Could it be because I am trying to copy from "InvoiceNumber"  field name to a different field "PreviousInvoiceNo"?  Thanks in advance.  Here is the complete macro code:

Private Sub Command144_Click()
Dim ID As Long
ID = OrderID
DoCmd.GoToRecord , , acNewRec

PreviousInvoiceNo = DLookup("InvoiceNumber", "TestOrderQ", "OrderID=" & ID)

ContactFirstName = DLookup("ContactFirstName", "TestOrderQ", "OrderID=" & ID)
ContactLastName = DLookup("ContactLastName", "TestOrderQ", "OrderID=" & ID)

BillToCompany = DLookup("BillToCompany", "TestOrderQ", "OrderID=" & ID)
BillToAttention = DLookup("BillToAttention", "TestOrderQ", "OrderID=" & ID)
BillToAddress1 = DLookup("BillToAddress1", "TestOrderQ", "OrderID=" & ID)
BillToAddress2 = DLookup("BillToAddress2", "TestOrderQ", "OrderID=" & ID)
BillToCity = DLookup("BillToCity", "TestOrderQ", "OrderID=" & ID)
BillToState = DLookup("BillToState", "TestOrderQ", "OrderID=" & ID)
BillToZip = DLookup("BillToZip", "TestOrderQ", "OrderID=" & ID)
BillToCountry = DLookup("BillToCountry", "TestOrderQ", "OrderID=" & ID)

ShipToCompany = DLookup("ShipToCompany", "TestOrderQ", "OrderID=" & ID)
ShipToAttention = DLookup("ShipToAttention", "TestOrderQ", "OrderID=" & ID)
ShipToAddress1 = DLookup("ShipToAddress1", "TestOrderQ", "OrderID=" & ID)
ShipToAddress2 = DLookup("ShipToAddress2", "TestOrderQ", "OrderID=" & ID)
ShipToCity = DLookup("ShipToCity", "TestOrderQ", "OrderID=" & ID)
ShipToState = DLookup("ShipToState", "TestOrderQ", "OrderID=" & ID)
ShipToZip = DLookup("ShipToZip", "TestOrderQ", "OrderID=" & ID)
ShipToCountry = DLookup("ShipToCountry", "TestOrderQ", "OrderID=" & ID)

VendorProductName = DLookup("VendorProductName", "TestOrderQ", "OrderID=" & ID)
VendorItemCode = DLookup("VendorItemCode", "TestOrderQ", "OrderID=" & ID)
ItemCode = DLookup("ItemCode", "TestOrderQ", "OrderID=" & ID)
Qty = DLookup("Qty", "TestOrderQ", "OrderID=" & ID)
VendorName = DLookup("VendorName", "TestOrderQ", "OrderID=" & ID)

Notes = DLookup("Notes", "TestOrderQ", "OrderID=" & ID)
VendorNotes = DLookup("VendorNotes", "TestOrderQ", "OrderID=" & ID)
DistributorNotes = DLookup("DistributorNotes", "TestOrderQ", "OrderID=" & ID)

SetUp = DLookup("Setup", "TestOrderQ", "OrderID=" & ID)
MiscItem = DLookup("MiscItem", "TestOrderQ", "OrderID=" & ID)
MiscDescription = DLookup("MiscDescription", "TestOrderQ", "OrderID=" & ID)

CreditCardID = DLookup("CreditCardID", "TestOrderQ", "OrderID=" & ID)
CreditCardName = DLookup("CreditCardname", "TestOrderQ", "OrderID=" & ID)
CreditCardAddress = DLookup("CreditCardAddress", "TestOrderQ", "OrderID=" & ID)
CreditCardCity = DLookup("CreditCardCity", "TestOrderQ", "OrderID=" & ID)
CreditCardState = DLookup("CreditCardState", "TestOrderQ", "OrderID=" & ID)
CreditCardZip = DLookup("CreditCardZip", "TestOrderQ", "OrderID=" & ID)
CreditCardExp = DLookup("CreditCardExp", "TestOrderQ", "OrderID=" & ID)
CreditCardSec = DLookup("CreditCardSec", "TestOrderQ", "OrderID=" & ID)
CreditCardLast4 = DLookup("CreditCardLast4", "TestOrderQ", "OrderID=" & ID)

ProductName = DLookup("ProductName", "TestOrderQ", "OrderID=" & ID)
CompanyName = DLookup("CompanyName", "TestOrderQ", "OrderID=" & ID)


InvoiceNumber.SetFocus


End Sub


Reply from Alex Hedley:

Try creating the same sub but with just the InvoiceNumber. Break it down into the one thing you are having a problem with.

You've put a # in the question but not below. The Field doesn't contain a # does it? if so remove, they and other symbols shouldn't be used in Field Names.

So it's this line that doesn't work:

PreviousInvoiceNo = DLookup("InvoiceNumber", "TestOrderQ", "OrderID=" & ID)

Is 'PreviousInvoiceNo' a Number or Text Field?

If you put a break point in your code on this DLOOKUP what does it return?
Are you sure that's the correct spelling of the Field Name.
PreviousInvoiceNo Isn't an AutoNumber field in your new table is it?

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/15/2026 7:53:53 AM. PLT: 1s