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.
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 JakesOP
@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 JakesOP
@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.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visitor Forum.