+ Reply to Thread
Results 1 to 6 of 6

Run time error '400' form already displayed cant show modally

  1. #1
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Run time error '400' form already displayed cant show modally

    i am trying to call Userform in Module

    Dim cnt As ADODB.Connection
    Dim rst1 As ADODB.Recordset, rst2 As ADODB.Recordset
    Dim stDB As String, stSQL1 As String, stSQL2 As String
    Dim strConn As String
    Dim wbBook As Workbook
    Dim Sheet1 As Worksheet
    Dim i
    Dim lnField As Long, lnCount As Long
    Dim dataStr As String
    'Instantiate the ADO-objects.
    Set cnt = New ADODB.Connection
    Set rst1 = New ADODB.Recordset
    Set rst2 = New ADODB.Recordset

    Set wbBook = ThisWorkbook
    Set Sheet1 = wbBook.Worksheets(1)

    'Path to the database.
    stDB = "mysql32"

    'Create the connectionstring.
    strConn = "Driver=MySQL ODBC 5.2 Unicode Driver;" _
    & "Data Source=" & stDB & ";"

    BMS.Show -------------------------------------here calling my Userfom(BMS)

    'The 1st raw SQL-statement to be executed.
    'stSQL1 = "SELECT * FROM tblbatch_headers where idBatch " & batchID & "order by col_seq asc"

    'The 2nd raw SQL-statement to be executed.
    stSQL2 = "SELECT * FROM " & BMS.TextBox1 & " where FQR_User_Code='" & Environ("userName") & "' and line_status in('QP')" '
    'Clear the worksheet.
    ' Sheet1.Range("A3:FA3").CurrentRegion.Clear

    With cnt
    .Open (strConn) 'Open the connection.
    .CursorLocation = adUseClient 'Necessary to disconnect the recordset.
    End With

    With rst1
    ' .Open stSQL1, cnt 'Create the recordset.
    Set .ActiveConnection = Nothing 'Disconnect the recordset.
    End With

    With rst2
    .Open stSQL2, cnt 'Create the recordset.
    Set .ActiveConnection = Nothing 'Disconnect the recordset.
    End With

    With Sheet1
    ' .Cells(2, 1).CopyFromRecordset rst1 'Copy the 1st recordset.
    For i = 2 To rst2.Fields.Count
    '.Cells(2, i).Value = rst2.Fields(i - 1).Name
    Next i
    .Cells(3, 1).CopyFromRecordset rst2 'Copy the 2nd recordset.
    End With

    'Release objects from the memory.
    ' rst1.Close
    ' Set rst1 = Nothing
    rst2.Close
    Set rst2 = Nothing
    cnt.Close
    Set cnt = Nothing

    With Sheets("Sheet1")
    .Unprotect "password"
    .Cells.Locked = False
    .Columns(2).Locked = True
    .Columns(3).Locked = True
    .Columns(4).Locked = True
    .Columns(5).Locked = True
    .Columns(6).Locked = True
    .Protect "password", AllowFiltering:=True
    End With


    End Sub

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Run time error '400' form already displayed cant show modally

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Unless you have set the ShowModal property none of the code after the show will execute until you close the userform.

    I suspect the problem is in code within the userform, which we can not see.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: Run time error '400' form already displayed cant show modally

    sorry for that

    This is the code i in userform button
    Please Login or Register  to view this content.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Run time error '400' form already displayed cant show modally

    You really need to post a workbook or all the code.
    I don't know whether the latest excerpt is the initialize event or just code in a routine within the userform code module.

    You could try stepping through the code line by line from the .Show

  5. #5
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: Run time error '400' form already displayed cant show modally

    see i have attached my workbook
    Attached Files Attached Files

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Run time error '400' form already displayed cant show modally

    You have a BSM.Show command in the commandbutton1_click event, which you appear to have commented out.

    The userform is already loaded and displayed so that command is not required.

    Does the example you posted actually generate the error? Obviously I can not fully test as I can not make the db connections.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how to show (time) of cells to the listbox of a form
    By chinrose in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2011, 04:17 AM
  2. Form already displayed error and Setting a Value to a cell in Excel
    By saj121 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2010, 07:09 PM
  3. Form Show Error
    By gti_jobert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-24-2006, 10:03 AM
  4. [SOLVED] Show/Hide Causes Error on Form Close
    By Trip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2005, 07:10 PM
  5. Type mismatch error on form show
    By Darach in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2005, 08:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1