Computer Learning Zone CLZ Access Excel Word Windows

Education is not the filling of a pail, but the lighting of a fire

-W.B. Yeats
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Cmd Open Form to New Order
George Jakes 

2 years ago
Hello. First, let me say thank you for answering my first 2 questions. secondly, let me also say that I've been trying and retrying to get this right. Even googling it.
All I'm trying to do is to create a cmd button to create a new order for the client record currently open. From the client window. I even found the exact code on one of your videos. But out of the two lines of code, the top one just won't work. It's asking for macro info when I run it.

Here's the code:

Private Sub neworderbtn_Click()
Docmd.openform "OrderF", , , "CustomerID=" & CustomerID
DoCmd.GoToRecord acDataForm, "OrderF", acNewRec
End Sub

What am I doing wrong? I've double, triple, more than quadruple checked this over.
Thanks in advance.

Sami Shamma  @Reply  
             
2 years ago
Try this:

Private Sub neworderbtn_Click()

Docmd.openform "OrderF", , , "CustomerID=" & CustomerID, acFormAdd

End Sub
Kevin Robertson  @Reply  
          
2 years ago
It's asking for macro info when I run it.

What is Access asking? What Info?
George Jakes OP  @Reply  

2 years ago
At first it was opening a window asking for a macro, looking in the file that I've created.
Now it give me an error. After clicking on it I get the following error:
Run time error 2105
You can't go to the specified records

the debuuger then highlights my second line of code.

And, I've tried the code that you created, narrowing it down to one line. A new order does open, but not with the client ID of the client that's open.
Kevin Robertson  @Reply  
          
2 years ago
For the form you are opening to get the ClientID you need to set a Default Value
George Jakes OP  @Reply  

2 years ago
Thank you for the default value recommendation. I set clientid and customername to the value of the same fields in customerF, then created a macro to open the form with data mode set to add. And it works great.
I'm just wondering why I couldn't do it through code? Richard created a video to do just that, with the same forms, tables, and fields that I'm working with. That's strange.
I did take some notes of what it was doing when I was trying to get the code working. And this is what it was doing with Sami's code suggestion, when I entered it and ran the debug.
I would get a window that appeared. It looked like it wanted me to choose a macro. But there weren't any macros in the window that appeared. The window that appeared was as follows:
Macro Name:
(empty box under that)
(empty window under that)
cmd  buttons to the right of these boxes
run (grayed out)
cancel
step into (grayed out)
edit (grayed out)
create (grayed out)
delete (grayed out)
Kevin Robertson  @Reply  
          
2 years ago
Perhaps the Button still had the Macro attached. Without seeing it I couldn't really tell you.
Try adding a new Button (cancel the wizard). Add the code to the Click event of this Button.
George Jakes OP  @Reply  

2 years ago
That's a great suggestion. I just tried that. Same result. I tried it, same result.
Then I created a brand new DB with two tables, two forms. It took a little work, but I got it working. So there's something up with the database that I'm working off of.
That's good to learn. Thanks for getting me there. I'm going to see if I can find the culprit.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor 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/6/2026 12:07:34 PM. PLT: 2s