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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating DialogBox forms in Access 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

Is it possible to create a form as a DialogBox as in VB.

Or do you simply have to create a normal form and use the 'OnClose' event?

If I have a function which needs to open a dialog box and depending on whether certain info is provided, I need to stop running the function?

How do you do this in Access, the same way as using DialogBoxes in VB.

Thanks,

1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Did you set the PopUp property of the form to True ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV, yes I did.

I have set my form to 'popup' and 'modal' , but I understood these just make the form appear over any other open form and forces you to close the popup form before you can navigate else where or bring other open forms to focus.

I've done a bit of Googling, and it seems that a form when closed in VBA no longer has its controls available like a true DialogBox would.

I guess as you don't instantiate a DialogBox object against a variable as you would in VB, Access doesn't work in the same way.

But please correct me if i'm wrong.

I've read in VBA you just open a form in the normal way, set an OK button to hide the form, then process the data on the form, then close it via code.

or is there a built in mechanism with Access forms to make them work the same way as standard VB DialogBoxes?

I currently have my form code as follows....
Code:
                '1st check for override
                If sMSG <> "" Then
                    If vbYes = MsgBox("The following is either missing or outstanding..." & vbCrLf & vbCrLf & sMSG & vbCrLf & "Do you wish to override termination requirements?", vbYesNo) Then
                        DoCmd.OpenForm "Termination_Override"
                        Forms!Termination_Override.Visible = True
                        Do While Forms!Termination_Override.Visible
                            DoEvents
                        Loop
                        If Nz(DLookup("Termination_Override", "Contacts", "ContactID = " & Me.ContactID), "") <> "" Then
                            sMSG = ""
                        End If
                    End If
                End If
                
                '2nd check - cancel termination
                If sMSG <> "" Then
                    MsgBox "Unable to terminate AR due to outstanding requirements which have not been overridden!"
                    Exit Sub
                End If

so i have a string variable sMSG which I add info to as i check certain form field values, if the sMSG is not an empty string then it asks if you wish to override.

If 'yes' is selected, it opens the popup form and loops until it is closed (not visible). The popup form has a bound field on it, which is then checked via dlookup when the form is closed, if it is blank, it's assumed no reason for override was given (aka not overriden) otherwise it blanks the sMSG variable, the second check simply re-assesses the sMSG variable, if it still isn't an empty string the subroutine is exited so the rest of the code isn't executed.

any thoughts as to what i'm doing?

Cheers,
1DMF.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
you have to open the form in dialog by setting the windowmode to dialog using "acdialog"

Modal does not stop running code on its own. All it does is prohibit any other form or report from getting focus.

acDialog opens a form as if its Popup property were set to true, and as if its Modal property were set to true, and also adds the behavior of pausing the calling code that opened the form until the form is closed or made hidden.

No combination of Popup and Modal will produce that behavior if the form is not opened with the acDialog argument.

 
ok, made a booboo as the code errors when the form is closed as it is looking for 'visible' property of a form which no longer exists.

Luckily i have a function 'IsLoaded' which checks a form is loaded, so i have changed my code to ...
Code:
                        DoCmd.OpenForm "Termination_Override"
                        Do While IsLoaded("Termination_Override")
                            DoEvents
                        Loop
It performs as desired, but am still open to better suggestions.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
why not change

DoCmd.OpenForm "Termination_Override"
Forms!Termination_Override.Visible = True

to
DoCmd.OpenForm "Termination_Override",,,,,acDialog
'code pauses here

Why not do like you suggested, that is the way I would do it.
1)open the form dialog (halt code execution)
2)Have an OK button (hides the form, but still open. Code resumes in calling form)
3)Check to see if it is loaded (but hidden)
4)Return values since loaded
5)Close the hidden form

The only reason I would do it your way is if I had multiple form instances of the same form, but it does not appear that way. Do you?
 
Hey MajP.

Well as I understood looking at MSDN, acDialog, does exactly the same as setting 'PopUp' and 'Modal' , does it really matter which way you set these properties?

I did think about doing it that way, only how do I deal with the user clicking [x] and closing the form?

As the field is bound to the popup form and I have 'Me.refresh' in the Form_Close event to ensure the backend SQL DB is updated with any entry into the form.

I decided to not have any buttons on the form, just the override 'memo' field.

The only way to close the form is by the [x] and then check the DB to see if the field has any data in it upon form close.

How would you deal with users clicking [x] and closing the form, if trying to use the 'visible/hide' form method?

Remember it's possible to enter data into the popup form field and then click [x], doing it as you suggest and I intially considered doesn't cover this possible scenario.

Ok and no! I cannot remove the close button [x] , every form in the entire DB has them, a complete redesign to make all forms consistent with full 'control box' features (min/max/close) was done a while back, so I need to be consistent.

hmmm, is it possible to stop a form closing via the form_close event handler and simply make it hidden instead?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
dang I missed this post
acDialog opens a form as if its Popup property were set to true, and as if its Modal property were set to true, and also adds the behavior of pausing the calling code that opened the form until the form is closed or made hidden.

I didn't realise it pauses execution until form is closed, I never saw that on MSDN when looking, then again, I am a bit blind when it comes to reading things!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
I do this a lot so I have a lot of forms with an OK button that hides them. So I have a generic function that I can use (assuming I only want to return a single value from the form. I could modify it to return an array of values from different fields if needed)
Code:
Public Function valueFromForm(frmName As String, ctrlName As String) As Variant
  DoCmd.OpenForm frmName, , , , , acDialog
  'code execution halts until calling form closes or is hidden
  If CurrentProject.AllForms(frmName).IsLoaded Then
    valueFromForm = Forms(frmName).Controls(ctrlName)
    DoCmd.Close acForm, frmName
  End If
End Function


Public Sub HowICall()
  Dim tempX As Variant
  tempX = valueFromForm("categories", "categoryName")
  'had to hit OK and there is a value to return
  If Not IsNull(tempX) Then
    'assign value to calling form field
    'me.someField = tempX
  End If
End Sub
 
Thanks MajP,

Seems simple enough, but still doesn't handle when data is supplied but [x] is clicked.

As the variant array of form controls are only assigned if the form is loaded!



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
So when I do this on my dialog forms I remove the X (close button) and usually the whole control box. Then I only have an OK and Cancel button. (I make it look consistent throughout the DB)

OK: Me.visible = false
Cancel: docmnd.close acform, me.name

If you do not like that technique the other one is just to use a global variable, but controlling it is a little trickier.

public glblReturn as variant

Then when your OK / or close
glblReturn = someValue

From the calling form to ensure a proper return
'null it out first
glblReturn = Null
docmd.openform "yourForm",,,,,acdialog
if not isnull(glblReturn) then
code here
end if

But by doing this you are saying X means the same as OK, or you can set it up so that X means cancel and only set the value if you hit ok.
 
It's just a company decision was made that ALL forms should be consistent and have the min/max/close 'control box'.

We used to have a right mish mash of some having the control others having that little exit door symbol, part of my VB course has taught me to allow the control box by default, but then again, in VB you can instantiate dialog boxes and deal with them when closed (as they aren't really closed), you need to use
Code:
myDialogBox.dispose()
to have it garbage collected.

Global var is an option i guess, so you have certainly given me plenty to be getting on with.

just using the acDialog, was a great help, so thanks for your valuable input!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top