Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Helm making record macro button

Status
Not open for further replies.

kuebs

Technical User
Mar 6, 2002
15
US
I am really new at macros. Can someone tell me how to make a macro button for a form that will jump the user to a new record? My form opens up into existing records and they are getting overwritten. And the users can't seem to get the little buttons down on the bottom of the form.
 
use the button wizard and it will show you... or place this vba code behind the button:

DoCmd.GoToRecord , , acNext

cheers
wah
 
Thanks for helping me, I tried that but, it did not work for me. I tried putting that code in expression builder, but it kept telling me it was invalid. I am using Access 2000.
 
Advice - forget about macros. Sooner or later they'll jump up and bite you.

Use the command button wizard on the Form Design toolbox to place an "ADD RECORD" button on your form. You can also do a "UNDO", a "CLOSE FORM" and a host of others as well. Access will write the two or three lines of VBA code that you need for each one. Its a good way to learn, and is more reliable than macros.

"Remember, you're unique - just like everyone else"
You're invited to visit another free Access forum:
or my site,
 
Thanks. I tried that again, but it failed. What I didn't mention before, because it is something I tried over a week ago, was that I have used the button wizard, and made a button that did add new record. After I save it and click on the button, it says the button click produced and "Invalid Outside Procedure". Any thoughts? I didn't touch anything after I used the button wizard.
 
Hmmm. Sounds like you might have a ghost in the machine - can you post your code here?

The "Invalid outside procedure" means that somewhere you have a chunk of code or maybe just one or two words, that somehow slipped out of their Sub...End Sub boundaries and are just sitting there. Access trips over them while scanning a module or something, and says, Hey! This is not right! It's outside of a procedure1!

You didn't happen to go into the code and play around a bit after the wiz was done, did you? It's amazing sometimes how much damage an inadvertent cut and paste can do...[smile]

"Remember, you're unique - just like everyone else"
You're invited to visit another free Access forum:
or my site,
 
OK, here is the code. And thanks for all the help.

Private Sub Command127_Click()
On Error GoTo Err_Command127_Click


DoCmd.GoToRecord , , acNext

Exit_Command127_Click:
Exit Sub

Err_Command127_Click:
MsgBox Err.Description
Resume Exit_Command127_Click

End Sub
Private Sub Add_New_Record_Click()
On Error GoTo Err_Add_New_Record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_New_Record_Click:
Exit Sub

Err_Add_New_Record_Click:
MsgBox Err.Description
Resume Exit_Add_New_Record_Click

End Sub
 
Ok - not sure which is your most recent, but both of those guys look ok. They do the same thing, looks like you might have renamed one of them later on. Judging by the Command127 name, it looks like you've been wrestling with this form for a while...

Here's what I'd like you to do. Open the form this is on, and go into your module editing mode - not sure if you're using A97, A2K or A2K2, but you need to be in the code for the form. What you do next will depend on which version you use:

A97: Click on DEBUG/Compile Loaded Modules or click the Compile loaded modules toolbar button.

A2K: Click DEBUG/Compile on the VB editing menu.

This operation will compile all your code, specifically the code in this form - it SHOULD blow up somewhere on the line that's "invalid outside procedure" -

Copy and paste about 15 lines above and below where you get the error and post it here. We'll take a look.

Somethings just not right, because your button SHOULD work.
"Remember, you're unique - just like everyone else"
You're invited to visit another free Access forum:
or my site,
 
You were dead on right! At the very top of the code, was a NEW RECORD line. Not sure how it got in there, but you had to scroll up to see it. After I deleted it, the button worked fine. You the MAN!
 
I've seen more head-scratchers caused by accidental Copy/Paste operations than almost anything else. I do 'em all the time too, cause my flying fingers don't always watch what they're doing. I'm just so used to it now I know where to look for the offending line(s)...[smile]

"Remember, you're unique - just like everyone else"
You're invited to visit another free Access forum:
or my site,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top