|hcs consulting group.|
|we make complex systems simple|
by albert d. kallal
friday, june 04, 2004
dialog and prompt forms in access.
the following prompt form information is likely one of the best things you can learn to improve your ui in ms-access.
of course with access, we have what we call event driven programming. you click on a button, and some code runs. as normal course of things, this is usually a good thing. however, often we do want some procedural type things to happen. you might want to pop up a form to ask for a date, or date range, or even have a custom yes/no box that has additional features that you don't have with built in dialog boxes, and the built in input box.
the reason why we find the built in msgbox, and the built in input box so handy is that they are dialog boxes.
dialog boxes in ms-access are so often confused with modal forms. a modal form is a form that keeps the focus, and you must close that form to return to where you came from. this setting is found in the forms "other" tab. often, when you have a series of forms you need to force the user to return back the way they came from, you use the modal setting to accomplish this.
a dialog box, or a dialog form on the other hand is quite a bit different. in fact, they are very different from modal forms. do not confuse the two!!! they are very different, and have very different uses. further, the only way to open a form in dialog mode is to use:a form in dialog mode is to use:
for a modal form, this is a setting you find in the forms "other" tab of the properties sheet. again, i can't stress how different these two features are, yet, many ms-access users, and even some developers are still confused about these two different features. so, the modal setting of the form is not really done via code (but by simply using the "other" tab). further, the docmd.openform does not have any provisions for setting the modal option (but, it does let you set the acdialog feature). so, modal forms, and acdialog forms are very different.
first, when you pop up a msgbox, (or a dialog form), you are stuck in that dialog. you can't even use the menu bar, can't right click, in fact can't do anything else!!. so, a dialog form is much more nasty then is a modal form. so, in code when you open up a msgbox, or a dialog form, the code halts and waits for the users input. it is important to note that nothing else can occur. a modal form on the other hand allows full use of menus, and of course does not halt code.
part time home jobsTaking on additional projects and clientsonline jobs work from home part time no experience
if we open a form, and want to set some datefield to today, we can go
forms!mycoolform!mycooldate = date()
the above of course opens the form, and the code continues to run..so we can actually setup, or do things to that form.
online work for house wifeOnline Translation:easy online part time jobs from home
often, for re-usable code, and forms, we would like the above form to wait for the user done with the form.
online encoder work from homeFreelance Writing:part time jobs near me for students
this means we can build forms that ask users for info, and have that form return the values back without using a bunch of global vars, or other weird things.
here is how you do it. you open the form in acdialog mode. this will
halt the calling code, and wait. the user then enters some data into fields,
and the hits the ok button. the trick here is that the ok button does not
close the form, but sets the forms visible property to false. the will cause
the form to drop out of acdialog mode, and then the calling code will
continue!. if the user does in fact hit you cancel button , or simply closes the form, you
consider that as a cancel!! (ie: the cancel, or even the "x" in the upper
right corner is thus considered a close/cancel).
so, lets say we need a form with a combo box, a check box..and some other things.
hence, the code looks as
' lets open a prompt form
strf = "frmgetcomboname"
' the above code opens our form "frmgetcomboname", and the waits until the user
enters some data, and then hits ok. the code behind the ok button in the
getname form does not close the form, but does
me.visible = false
' at this point, either the user hit ok, or closed the form. if the form is
still open, then user did not cancel, and we assume he hit ok
if isloaded(strf) = true then
' code goes here to example values
strname = forms(strf)!thenamefield
strsex = forms(strf)!genderfield
' ok, got our data...lets close the form (don't forget this!!)
' if the form is not open, then user hit the "x", or the cancel
' button on the frmgetcomboname form. note that the cancel button on
' this form simply does a docmd.close
msgbox "user canceled"
you also need the code for isloaded. it can be found in tons of examples,
and also in the northwind traders. it is reproduced below just in case
you don't have it:
you can also thus wrap the whole acdialog form code in a function that
returns a value if you want. (i do this for date calendar prompts, and
you thus get re-usable form that can be used anywhere by a simple function).
function fisloaded(byval strformname as string) as integer
'returns a 0 if form is not open or a -1 if open
if syscmd(acsyscmdgetobjectstate, acform, strformname) <> 0 then
if forms(strformname).currentview <> 0 then
fisloaded = true
albert d. kallal
edmonton, alberta canada
How can an 18 year old make money onlineIf you are bilingual, you can become a freelance translator. You can translate documents, websites, and other content for businesses and individuals. You can find translation jobs on platforms like TranslatorsCafe, ProZ, and Gengo.online part time jobs for students from home without investment
online part time jobs for students in mobile without investmentContent Writingonline work without investment