Results 1 to 10 of 10
  1. #1
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136

    Access shuts down as soon as i click on a command button

    When I click on a command button on my main form, access just shuts down.
    However, when I step through the code line by line, it works fine.

    Below is the code in concern - can this code cause access to shut down when you run it without stepping through it line by line?




    Code:
    Private Sub cmdOutputTrade_Click()
        DoCmd.OpenForm "frmCustomReport", acPreview
        Forms![frmCustomReport].Controls("cboMyTables") = "Trade Exposure Report"
        Forms![frmCustomReport].Controls("lstMyFields").RowSource = "MergedTradeReport"
        Forms![frmCustomReport].Controls("lstMyFields").Requery
        DoCmd.OpenForm "frmCustomReport", acNormal
        SelectItemsInAListBox "Trade_Exposure_Report"
    
    End Sub

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    What is the purpose of the code as it makes no sense to me.
    Is it running from frmCustomerReport or another form?

    Opening a form in preview mode just shows you what it would like if you printed it. Perhaps you want acDesign insead?
    If you want to open a form with specified conditions you normally use OpenArgs
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Also what is
    Code:
    SelectItemsInAListBox "Trade_Exposure_Report"
    my guess is your problem lies there.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    why open a form, set control values, then open the same form again but with a different view??

    AFAIK, this
    Forms![frmCustomReport].Controls("cboMyTables")
    is a less efficient way of doing this
    Forms!frmCustomReport.cboMyTables

    I would comment out the call to the other function and run the code in the same fashion that causes the crash and see what happens.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    Quote Originally Posted by moke123 View Post
    Also what is
    Code:
    SelectItemsInAListBox "Trade_Exposure_Report"
    my guess is your problem lies there.
    this is a call to function called SelectItemsInAListBox passing a string parameter "Trade_Exposure_Report", that's all.
    its not causing the issue as I commented out that line, ran the code and it still crashes.

  6. #6
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    Quote Originally Posted by Micron View Post
    why open a form, set control values, then open the same form again but with a different view??
    The combo box in the form opens up with a default value set to "Limit Exposure Report".
    The combo box has 2 values - "Limit Exposure Report" and "Trade Exposure Report".

    Obviously, I want it to open up with the combo value set to "Trade Exposure Report" hence why I have this line in my code
    Code:
    Forms![frmCustomReport]![cboMyTables] = "Trade Exposure Report"
    .

    Then I need to set the row source of the list box (i.e. lstMyFields) in that form to this query I have called "MergedTradeReport" so that it is populated with the values as being the field names in that query "MergedTradeReport" and that's why I have this line in my code
    Code:
    Forms![frmCustomReport]![lstMyFields].RowSource = "MergedTradeReport"

    Anyways, I ran the below code with the call to the function commented out and still crashes:

    Code:
    Private Sub cmdOutputTrade_Click()
        DoCmd.OpenForm "frmCustomReport", acNormal
        Forms![frmCustomReport]![cboMyTables] = "Trade Exposure Report"
        Forms![frmCustomReport]![lstMyFields].RowSource = "MergedTradeReport"
        Forms![frmCustomReport]![lstMyFields].Requery
        'SelectItemsInAListBox "Trade_Exposure_Report"
    End Sub

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Do you have option explicit declared in each module?

    Code:
    Option Compare Database
    Option Explicit
    Is there any code that runs in frmCustomReport?

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    and if you step through the code, which line causes access to close?

  9. #9
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Similar to Ajax; Run only one line at a time. You need to find the error.

    If you don't know how to do this then ask. It is a tool that you will use many times in the future. So it is important that you learn.

    PS. For our benefit add some comments to explain what you are doing or trying to do.

  10. #10
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    The problem my lie with the code behind the Command Button or perhaps a problem with its properties.

    Suggest that you delete the Command Button then create a new one.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. External script to call Command Button Click event handler
    By Sean Nakasone in forum Programming
    Replies: 5
    Last Post: 10-29-2014, 12:35 PM
  2. Replies: 3
    Last Post: 04-19-2013, 07:09 AM
  3. Replies: 5
    Last Post: 01-15-2013, 07:28 PM
  4. Replies: 4
    Last Post: 04-14-2012, 07:22 PM
  5. Command button click event
    By R_jang in forum Programming
    Replies: 10
    Last Post: 10-29-2010, 10:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums