Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Help with Excel UserForm

Hi everyone,

In my code below, what I am trying to accomplish is to have a form
popup that states "Please wait..." while my combo box is being
populated. When I run my code, my popup box hangs until I click the
close "X" button on my form, then a error message comes up and states:

Error 402: Must close or hide topmost modal form first.

Can anyone tell me what I am doing wrong?

Private Sub cboProdLine_AfterUpdate()
Dim Conn As New ADODB.Connection, rst As ADODB.Recordset, strSQL As
String
Dim Counter As Integer, RowMax As Integer, ColMax As Integer
Dim r As Integer, c As Integer, PctDone As Single

On Error GoTo cboProdLine_Change_Err

Me.cboProductCode.Clear

Conn.ConnectionString = "Provider=sqloledb;Data
Source=myDatabaseServer;" _
& "Initial Catalog=myDatabase;User Id=myID;Password=myPWD;"
Conn.Open

'Get the product line codes based on the plant selected
Set rst = New ADODB.Recordset
strSQL = "SELECT DISTINCT dbo.PlantProduct.ProductCode FROM
dbo.PlantProduct INNER JOIN dbo.Plant" _
& " ON dbo.PlantProduct.PlantCode = dbo.Plant.Code INNER JOIN
dbo.vwProductMasterWithVersioning" _
& " ON dbo.PlantProduct.VersionNumber =
dbo.vwProductMasterWithVersioning.VersionNumber AND" _
& " dbo.PlantProduct.ProductCode =
dbo.vwProductMasterWithVersioning.PRDNO INNER JOIN" _
& " dbo.vwProductVersionWithChildren ON
dbo.PlantProduct.ProductCode =" _
& " dbo.vwProductVersionWithChildren.ProductCode AND
dbo.vwProductMasterWithVersioning.PRDNO =" _
& " dbo.vwProductVersionWithChildren.ProductCode AND
dbo.vwProductMasterWithVersioning.VersionNumber" _
& " = dbo.vwProductVersionWithChildren.VersionNumber INNER JOIN
dbo.vwProductLineConversion ON" _
& " dbo.vwProductMasterWithVersioning.CLASS =
dbo.vwProductLineConversion.CLASS AND" _
& " dbo.vwProductMasterWithVersioning.S2APH =
dbo.vwProductLineConversion.S2APH WHERE" _
& " dbo.Plant.Name = '" & Me.cboPlantCode.Text & "' AND" _
& " dbo.vwProductMasterWithVersioning.S2APH = '" &
Me.cboProdLine.Text & "'"

WaitForm.Show
rst.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
Me.cboProductCode.Clear
If rst.BOF = True And rst.EOF = True Then
MsgBox "There are no product lines associated with the plant " &
Me.cboPlantCode.Text & "."
Exit Sub
End If

rst.MoveFirst
Do Until rst.EOF
Me.cboProductCode.AddItem rst!ProductCode
rst.MoveNext
Loop
rst.Close
Conn.Close
WaitForm.Hide

cboProdLine_Change_Err_Exit:
Set rst = Nothing
Set Conn = Nothing
Exit Sub

cboProdLine_Change_Err:
MsgBox Err.Description, , "Error: " & Err.Number
Resume cboProdLine_Change_Err_Exit

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Help with Excel UserForm

Try this:

WaitForm.Show vbModeless

This shows the form but does not halt ongoing execution while waiting for
the form to be closed.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"EAB1977" wrote in message
...
Hi everyone,

In my code below, what I am trying to accomplish is to have a form
popup that states "Please wait..." while my combo box is being
populated. When I run my code, my popup box hangs until I click the
close "X" button on my form, then a error message comes up and states:

Error 402: Must close or hide topmost modal form first.

Can anyone tell me what I am doing wrong?

Private Sub cboProdLine_AfterUpdate()
Dim Conn As New ADODB.Connection, rst As ADODB.Recordset, strSQL As
String
Dim Counter As Integer, RowMax As Integer, ColMax As Integer
Dim r As Integer, c As Integer, PctDone As Single

On Error GoTo cboProdLine_Change_Err

Me.cboProductCode.Clear

Conn.ConnectionString = "Provider=sqloledb;Data
Source=myDatabaseServer;" _
& "Initial Catalog=myDatabase;User Id=myID;Password=myPWD;"
Conn.Open

'Get the product line codes based on the plant selected
Set rst = New ADODB.Recordset
strSQL = "SELECT DISTINCT dbo.PlantProduct.ProductCode FROM
dbo.PlantProduct INNER JOIN dbo.Plant" _
& " ON dbo.PlantProduct.PlantCode = dbo.Plant.Code INNER JOIN
dbo.vwProductMasterWithVersioning" _
& " ON dbo.PlantProduct.VersionNumber =
dbo.vwProductMasterWithVersioning.VersionNumber AND" _
& " dbo.PlantProduct.ProductCode =
dbo.vwProductMasterWithVersioning.PRDNO INNER JOIN" _
& " dbo.vwProductVersionWithChildren ON
dbo.PlantProduct.ProductCode =" _
& " dbo.vwProductVersionWithChildren.ProductCode AND
dbo.vwProductMasterWithVersioning.PRDNO =" _
& " dbo.vwProductVersionWithChildren.ProductCode AND
dbo.vwProductMasterWithVersioning.VersionNumber" _
& " = dbo.vwProductVersionWithChildren.VersionNumber INNER JOIN
dbo.vwProductLineConversion ON" _
& " dbo.vwProductMasterWithVersioning.CLASS =
dbo.vwProductLineConversion.CLASS AND" _
& " dbo.vwProductMasterWithVersioning.S2APH =
dbo.vwProductLineConversion.S2APH WHERE" _
& " dbo.Plant.Name = '" & Me.cboPlantCode.Text & "' AND" _
& " dbo.vwProductMasterWithVersioning.S2APH = '" &
Me.cboProdLine.Text & "'"

WaitForm.Show
rst.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
Me.cboProductCode.Clear
If rst.BOF = True And rst.EOF = True Then
MsgBox "There are no product lines associated with the plant " &
Me.cboPlantCode.Text & "."
Exit Sub
End If

rst.MoveFirst
Do Until rst.EOF
Me.cboProductCode.AddItem rst!ProductCode
rst.MoveNext
Loop
rst.Close
Conn.Close
WaitForm.Hide

cboProdLine_Change_Err_Exit:
Set rst = Nothing
Set Conn = Nothing
Exit Sub

cboProdLine_Change_Err:
MsgBox Err.Description, , "Error: " & Err.Number
Resume cboProdLine_Change_Err_Exit

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Help with Excel UserForm

Show the UserForm as Modeless, then your pop-up will not error out.

Mike F
"EAB1977" wrote in message
...
Hi everyone,

In my code below, what I am trying to accomplish is to have a form
popup that states "Please wait..." while my combo box is being
populated. When I run my code, my popup box hangs until I click the
close "X" button on my form, then a error message comes up and states:

Error 402: Must close or hide topmost modal form first.

Can anyone tell me what I am doing wrong?

Private Sub cboProdLine_AfterUpdate()
Dim Conn As New ADODB.Connection, rst As ADODB.Recordset, strSQL As
String
Dim Counter As Integer, RowMax As Integer, ColMax As Integer
Dim r As Integer, c As Integer, PctDone As Single

On Error GoTo cboProdLine_Change_Err

Me.cboProductCode.Clear

Conn.ConnectionString = "Provider=sqloledb;Data
Source=myDatabaseServer;" _
& "Initial Catalog=myDatabase;User Id=myID;Password=myPWD;"
Conn.Open

'Get the product line codes based on the plant selected
Set rst = New ADODB.Recordset
strSQL = "SELECT DISTINCT dbo.PlantProduct.ProductCode FROM
dbo.PlantProduct INNER JOIN dbo.Plant" _
& " ON dbo.PlantProduct.PlantCode = dbo.Plant.Code INNER JOIN
dbo.vwProductMasterWithVersioning" _
& " ON dbo.PlantProduct.VersionNumber =
dbo.vwProductMasterWithVersioning.VersionNumber AND" _
& " dbo.PlantProduct.ProductCode =
dbo.vwProductMasterWithVersioning.PRDNO INNER JOIN" _
& " dbo.vwProductVersionWithChildren ON
dbo.PlantProduct.ProductCode =" _
& " dbo.vwProductVersionWithChildren.ProductCode AND
dbo.vwProductMasterWithVersioning.PRDNO =" _
& " dbo.vwProductVersionWithChildren.ProductCode AND
dbo.vwProductMasterWithVersioning.VersionNumber" _
& " = dbo.vwProductVersionWithChildren.VersionNumber INNER JOIN
dbo.vwProductLineConversion ON" _
& " dbo.vwProductMasterWithVersioning.CLASS =
dbo.vwProductLineConversion.CLASS AND" _
& " dbo.vwProductMasterWithVersioning.S2APH =
dbo.vwProductLineConversion.S2APH WHERE" _
& " dbo.Plant.Name = '" & Me.cboPlantCode.Text & "' AND" _
& " dbo.vwProductMasterWithVersioning.S2APH = '" &
Me.cboProdLine.Text & "'"

WaitForm.Show
rst.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
Me.cboProductCode.Clear
If rst.BOF = True And rst.EOF = True Then
MsgBox "There are no product lines associated with the plant " &
Me.cboPlantCode.Text & "."
Exit Sub
End If

rst.MoveFirst
Do Until rst.EOF
Me.cboProductCode.AddItem rst!ProductCode
rst.MoveNext
Loop
rst.Close
Conn.Close
WaitForm.Hide

cboProdLine_Change_Err_Exit:
Set rst = Nothing
Set Conn = Nothing
Exit Sub

cboProdLine_Change_Err:
MsgBox Err.Description, , "Error: " & Err.Number
Resume cboProdLine_Change_Err_Exit

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
fill userform textbox from userform listbox clik event GregJG[_21_] Excel Programming 3 December 7th 08 04:47 PM
Is there an easy Copy/Paste of a Userform ? (Entire Userform Including tx & cbx's) Corey Excel Programming 2 January 9th 07 01:01 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM
Linking userform to userform in Excel 2003 missmelis01 Excel Programming 2 August 27th 04 08:07 PM


All times are GMT +1. The time now is 08:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"