• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1722
  • Last Modified:

Converting Macros to VBA in Access 2007

I am creating a simple form to use in Access 2007. I have buttons on the form for next record, previous record, save record, etc. If I create the button using the wizard it works fine, and I am able to navigate through the records. However, I need to add additional code to the buttons so they can do what I want them to do. When I convert the macro to VBA and try to use the buttons, they no longer work. I created a form like this in Access 2003 and did not have any problems. Then again in Access 2003 I wrote the code for my buttons myself. I can tell that the code has changed a little in Access 2007, but why do my buttons stop responding as soon as I change to VBA?
0
MYCU
Asked:
MYCU
  • 6
  • 6
  • 2
4 Solutions
 
BadotzCommented:
Did you link the button's ONCLICK event to the VBA code?
0
 
MYCUAuthor Commented:
The OnClick Event says event procedure. Is there someting else I need to do?
0
 
BadotzCommented:
Make sure the event procedure points to your VBA code.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MYCUAuthor Commented:
How do I do that?
0
 
BadotzCommented:
Click in the box that says [Event Procedure] for the event you want to sink - presumably "On Click".
Click the elipsis (...) to open the VB IDE, and point the event code to your VBA code (or copy your VBA code into the event stub).
0
 
Jeffrey CoachmanMIS LiasonCommented:
Yes, as Badotz says, you must copy the converted code to the Event.

Just converting the macro to VB does not "replace" the existing Macro for the event.

The converted maco will be in a module of the same name.
Something like "ConvertedMacro_YourMacroName"

You must copy this code and put in on the associated event.

But navigation code is simple, there really is no need to convert it.
Basic navgation code:
    DoCmd.GoToRecord acDataForm, ,acFirst  'Goes to the First Record.

other arguments are:
acLast
acPrevious
acNext
acFirst
acNewRec

So just delete the Macro code on the event and save the form, then go back to the event and click the build button ( [...] ), select "Code Builder", and type code similar to what I have above.

;-)

JeffCoachman
0
 
MYCUAuthor Commented:
Ok Thanks. I got it!
0
 
BadotzCommented:
Grade "B"? Was I bad?
0
 
MYCUAuthor Commented:
No you weren't bad. Just a little short with your answers. I am new to Access 2007 so the coding is a little different. I was having problems with my code and decided to just create a button through the wizard and see if that worked.....and it did. But like I said before, I needed to add additional code for my buttons, and that is where I was running into problems.

I don't work with macros because their functionality is limited. I figured once I converted the macro to VBA everyting would work properly and it didn't. That is were you guys came into play. I guess I was looking for more of an explanation on how to fix this issue, and you were just a little too brief.

Anyway, I'm glad you were there to assist me and I really appreciate your help. A "B" is not a bad grade.
0
 
BadotzCommented:
If I was too brief, why didn't you ask me for more details?

How are we to interpret, "Ok Thanks. I got it!"? To me, this sounds like you grokked the answer, and were happily on your way.

If not, then why did you award points?
0
 
MYCUAuthor Commented:
I did get the answer and was happily on my way. Once I checked the posts again I saw both yours and boag's. Yours was a little brief and his was a little more detailed. Regardless, I still fixed my issue and everyting is working fine. I awarded points becuase my issue was resolved.
0
 
BadotzCommented:
Whatever...
0
 
MYCUAuthor Commented:
I don't think I should have to beg for a detailed answer. I expect it because you all are supposed to be the experts. The other person who responded to my post has not sent any compalints. Next time I'll be sure to give you an "A" regardless of how brief your answers may be.  
0
 
Jeffrey CoachmanMIS LiasonCommented:
OK,

I'll weigh in...

First I will say that I rarely look at grades unless I know I really had to do a lot of work on my own to get the solution to the asker.

My first impression was that this was an "Average".
Meaning an "A" for Badoz and a "C" for me.

Obviously the grading here is "subjective".
Meaning the grade is what the asker thinks the answer was worth.

That being said...
With the abundance of "Unlimited" points, most askers simply set the question points to the max (500) and assigning a grate of "A" if the answer "works".

With this, many experts now "expect" an A grade for every correct answer.
This means that with the overwhelming number of A grades, a B has gotten a bad rap.


Now that is not to say that if an asker thinks the answer is worth a B, then they should feel obligated to assign an A.

As long as the asker is willing to justify the grade, I'm OK with it.

So the issue becomes that some people consider an a to be "perfect".
Now since no one is perfect, ...a B grade should be fine.

Again, if the asker can justify the B (or even a C), then I'm fine with it.

From a site wide perspective, "Hungry" experts may start to ignore the questions of an asker who consistently grades B,  and does not defend the grade.
In the same way that a lot of experts here now ignore any question that is not 500 points.

Is this fair?
No.

Is it reality?
Yes.

It has been discussed that some question will only warrant a B grade.

If a person asks "Can I change the color of a combobox?" and I answer: No.
Is that really worth an A?

Suppose the asker asks: "How do I filter a report with a combobox?"
And I simply post a link: http://www.fontstuff.com/access/acctut08.htm
... is this worth an A?

Suppose I posted the link and gave a full explanation, is that worth an A+?

So you can have a thread that lasts for 30 back and forth posts, where the expert and the asker are in constant contact, and that get an A.
Then you have a "One Link" post, also worthy of an A.

So if I say "Use a recordset to loop through all the customers and send them an email" and that is the correct answer, some might accept that and grade an A.

But that post pales in comparison to a post where the actual loop code is posted, a full explanation is given, and step by step instructions are listed.

There was a famous post here where Expert  B stated that the post "You need to use code to do that" was a valid answer, and worthy of an A grade because that was the answer.
But the asker actually accepted Expert C's post because a sample file and a full explanation were given.

So in an attempt to be fair and diplomatic, I will make these two statements:

From an Expert's standpoint I try to throw my best post right up front, full explanations, Links, samples ...ect.
This way, if I get a B, I can say "Hey, I provided full explanations, Links, samples ...ect."
;-)
A wise expert once said: "There will always be another question"

From and Askers point of view, I try to set all my requirements up front as well.
If I want full explanation, I will say so in my initial question..
This way if no explanation is posted and only a "link" is given, I can "Justify" my B grade by saying: "Hey, I asked for a full explanation."
I also must really think about my grading if I find myself constantly bombarded with requests to "Explain my grade".
Here to, I would know that, there will always be an expert willing to answer my question regardless of the points value and accept a justifiable grade.

Just my 2c.

;-)

JeffCoachman
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now