Command Button in Database

E

excel_hari

Hi,

Im doing some lookup kind of operation by exporting 2 excel files in to
access and then after lookup, the results (from a query) are exported
as excel fle. All this has been dne within VBA.

I dont want my user to press alt + F11 and then run the selected
module/macro. I want to know as to whether I can offer user a button in
the data base itself whereby as soon as it opens the user can click on
it and generate the output in excel. :-

a) Presently I had to make a form in which I created a command button
with underlying code calling up my Lookup module/macro. It works
perfectly. But, I dont like this method as user would have to first
cick on the form and then press the button. In excel one could keep the
button on the worksheet. In Access how does it work. Cant we have a
button in the white space when a new DB is opened or in the gray space
where the objects are listed on the left hand pane. (The command button
Toolbox is greyed out in these cases).

b) Also, in situation like mine, is it more "appropriate" to create
command button in a FORM or witin a REPORT (I see that I have command
buttons available even within Report). I havent worked with databases
in a formal environment.

Regards,
HP
India
 
S

strive4peace

Command buttons need to be on forms

Usually, the main menu form is specified to open when you
open the database ...

Tools, Startup...

In order to assign a general procedure to the OnClick
property directly, it must be a FUNCTION...

OnClick -->
=MyFunctionName()


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
E

excel_hari

Crystal,

Thanks for your suggestions.

I have added my form to Startup. Now, when I open the DB, then I dont
have the form occupying the maximum possible window space. I have to
click on the Square box in the right hand top corner to maximise the
size of the form. How do I set it so that everytime I open the Database
the user gets to see it in maximized form.

Please guide me.

Regards,
HP
India
 
S

strive4peace

Hi HP,

make a macro

Name --> AutoExec
Action --> Maximize

This will automatically execute when the database is opened

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
E

excel_hari

Crystal,

I could get the following code and it works well. I want to know one
thing. Why is it that default action for a Form is not in maximize
position. Cant that be somehow controlled by setting the form
properties somewhere?


Function Autoexec()
On Error GoTo Autoexec_Err

DoCmd.Maximize


Autoexec_Exit:
Exit Function

Autoexec_Err:
MsgBox Error$
Resume Autoexec_Exit

End Function

Regards,
HP
India
 
E

excel_hari

Crystal,

I have one follow up doubt.

I was using the autoexec code above and then a thought came to my head.
Once it gets maximized and after that if I immediately exit out of the
DB, then am not asked as to whether I want to save the DB. S, this
means either of 2 things:-

a) In access the maximixing action is not considered as part of "DB
structure", so thats why while exiting out access doesnt prompt for
saving the maximized form.

OR

b) In access the maximixing action is considered as part of "DB
structure" and probably these things are autosaved, so thats why while
exiting out access doesnt prompt for saving the maximized form.

To check my hypothesis, I opened my DB and then I did Alt + F11 and
then commented out my Autoexec macro (for Form maximizing) and then
saved and closed the VB editor and then exited out of the DB. Next time
I opened the DB, the form was in maximized form!!!

So it seems that probably point b) is correct. But if that were true,
then when I didnt have any autoexec code and had saved the DB after
maxming form and reopned DB then it never used to be in maximized form.

I cant understand as to whats the explanation here?

Regards,
HP
India
 
S

strive4peace

Hi Harry,

you can put the following in the form LOAD (or OPEN) event

DoCmd.Maximize


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
S

strive4peace

Hi Harry,

maximizing os not part of the form definition

think of it this way: defaults are often like settings on
the dashboard of your car. If you like a particular radio
station, you press button "1" -- another person might press
button "2"... or you might scan for a different channel You
like the temperatire cooler, so you might not turn the
heater on -- another person may choose to have heat.

The bottom line is this: WHERE you are going and how fast
you get there is not affected (directly)....
of "DB structure" <<<

not true




Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
S

strive4peace

you're welcome ;) happy to help

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top