2
votes

I'm trying to write some code for my database to enable a dropdown box in a parameter prompt for a query, but it's doing nothing instead of it's intended purpose. This:

Dropdown in Access 2007 parameter query

has been the source of my inspiration. Though I seem to be unable to implement even the most basic VBA code:

  Private Sub cmdReset_Click()
    Me.cboSelectName = Null
  End Sub

(Yes this is not all my code! Just one of the subs)

On the relevant form, I have a button called "cmdReset", which has "[Event Procedure]" for the event "On-Click". I also have a dropdown box called "cboSelectName" on said form. Also I have tried closing the database, and making sure to enable macros when it starts.

So essentially this code should make the value in the dropdown box null when I click the reset button. However it does nothing, it simply deselects the dropdown box. Can anyone help me with this one? I'm keen to start implementing some VBA in my database!

1
Click on Private Sub ... and click F9. This sets a breakpoint. Run your form and click the command button, does the code window open up? The breakpoint allows you to find out of the code ever arrives at that point.Fionnuala
Have you tried Me.cboSelectName.Value = null or "" instead?Scotch
@Scott the default property of a control in VBA is value. You can add .Value if that is your coding style, but you do not need to.Fionnuala
@Remou you called it, the code wasn't even running. I figured out my problem - I had saved the code in a new module, rather than in the VBA for my form. Once I shifted the code into the form object, the reset button worked. The actual "generate report" command is running into a bug because of a naming issue, but I think I'll be able to sort that out myself. Thanks for the help all.andrewb
Hi andrewb You might like to post that as an answer, it could be useful to the next person, because you have covered most of the usual suspects in your well-written post.Fionnuala

1 Answers

1
votes

As suggested by Remou, the code wasn't even running. I figured out my problem - I had saved the code in a new module, rather than in the VBA code for my form. Once I shifted the code into the form object, the reset button worked. I've also now got some nifty code working with the actual "generate report" command. VBA really has the power to take your database to a whole new level!