Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2015
    Location
    Boston, MA
    Posts
    16

    Answered: acDialog Window Won't close.

    I am using an acDialog window to open a form that has a ComboBox that passes its value to a report. Everything works except that the dialog window won't close using the 'OK' button and the parameter value doesn't get to the report.

    This is the code for the report on-open event:

    Private Sub Report_Open(Cancel As Integer)
    ' variable for employee number to pass from combo box to query parameter. Now Public
    ' Public empNo As Integer

    ' open the combo-box form to select an employee
    DoCmd.OpenForm "SelectEmployee_Frm", WindowMode:=acDialog
    ' set the variable equal to the combo-box value
    empNo = [Forms]![SelectEmployee_Frm]![EmployeeSelect_CmbBox]
    ' close the combobox form
    DoCmd.Close acForm, "SelectEmployee_Frm"
    ' set the query parameter equal to the variable
    EmployeeRecord_Qry!EmpID = empNo
    ' open the training
    On Error Resume Next
    End Sub

    The code for the OK button is:

    Private Sub OK_Btn_Click()
    DoCmd.OpenQuery "EmployeeRecord_Qry", acViewNormal
    empNo = SelectEmployee_CmbBox
    DoCmd.OpenReport "EmployeeTrainingRecord", acViewPreview, , "LastName=" & Me!EmployeeSelect_CmbBox
    End Sub

    The report opens but with no data. When I close the dialog box the line
    empNo = [Forms]![SelectEmployee_Frm]![EmployeeSelect_CmbBox]
    raises an error. The correct query results then appear.

    Any help with what's causing the problem would be greatly appreciated.

  2. Best Answer
    Posted by healdem

    "
    Quote Originally Posted by healdem
    ...instead why not have a (simpler) form with, say a list of combo box. clicking /selecting that employee forcfes a report to open, but pass the employee ID/name as part of the open report macro's parameters...
    I agree...I really can't imagine trying to do this using the events in the Report, rather than in a Form.

    Linq ;0)>"


  3. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,399
    Provided Answers: 5
    what is the value of Me!EmployeeSelect_CmbBox

    try debug.print Me!EmployeeSelect_CmbBox to find out what it is


    change "LastName=" & Me!EmployeeSelect_CmbBox to "LastName='" & Me!EmployeeSelect_CmbBox & "'"

    note the '

    just before the End Sub
    do the docmd.close bla,bla,bla thing
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  4. #3
    Join Date
    Jun 2015
    Location
    Boston, MA
    Posts
    16
    Thanks Stephan.

    The debug method returns runtime error 2450 - can't find the referenced form - at the line "empNo = [Forms]![SelectEmployee_Frm]![EmployeeSelect_CmbBox]". The engine has just finished opening the form at the time.

    Adding the single quotes as you indicated changes the order in which the events happen but the end result is the same. Also, It then becomes the debug line that raises the (same) error.

    It's odd that it can't find an open form (I checked the spelling). I added a check to see if the form IsLoaded and the engine says it's not. But Googling the problem, it appears it's not uncommon. There just aren't any good answers out there that fit my case.

  5. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    [Forms]![SelectEmployee_Frm]![EmployeeSelect_CmbBox]

    sounds as if the whole purpose of the Form is to select an employee...if this is, in fact, its sole purpose, it would usually be an Unbound Form...is the Form Bound or Unbound?

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #5
    Join Date
    Jun 2015
    Location
    Boston, MA
    Posts
    16
    Yes, the form is unbound. It's purpose is to select an employee and pass that ID to the report so that the report is specific to that employee.

    - Bruce Hyatt

  7. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by healdem
    ...instead why not have a (simpler) form with, say a list of combo box. clicking /selecting that employee forcfes a report to open, but pass the employee ID/name as part of the open report macro's parameters...
    I agree...I really can't imagine trying to do this using the events in the Report, rather than in a Form.

    Linq ;0)>
    Last edited by Missinglinq; 08-01-16 at 18:50.
    I'd rather be riding on the Tiger 800 or the Norton

  8. #7
    Join Date
    Jun 2015
    Location
    Boston, MA
    Posts
    16
    That's essentially what I have. Thanks for the input though.

  9. #8
    Join Date
    Jun 2015
    Location
    Boston, MA
    Posts
    16
    So you were correct and that was part of the fix. If I open the dialog-box form with the unbound combo box and code the OK button as follows it works:

    Private Sub OK_Btn_Click()
    DoCmd.OpenQuery "EmployeeRecord_Qry", acViewNormal
    empNo = SelectEmployee_CmbBox
    DoCmd.OpenReport "EmployeeTrainingRecord", acViewPreview
    DoCmd.Close acForm, "SelectEmployee_Frm"
    DoCmd.Close acQuery, "EmployeeRecord_Qry"
    End Sub

    I had to remove "LastName='" & Me!EmployeeSelect_CmbBox & "'" from the OpenReport line. I guess because the report already gets its data from the query which has already run by the time the report is opened.

    Thanks for the help!

    - Bruce Hyatt

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •