PDA

View Full Version : Why would scrolling cause Application.InputBox "Cancel" behavior?



wolverineb
02-14-2010, 11:32 PM
Any thoughts on why this section of code would always branch to the "Is Nothing" branch simply because the user scrolled?

Basically, if there is any scrolling of any kind (scroll wheel, scroll bar, page-up/down), the dialog appears to continue normally (i.e. it allows the user to click on a cell, reflects that cell's address in the box, etc.), but then ALWAYS results in the InputBox's "cancel" behavior.

It works properly if no scrolling is done.

I have found a couple of other complaints about this, but only in obscure locations and always without an answer.


On Error Resume Next
Set rngShopOrderToMove = Application.InputBox(sMessage1, gsAPPNAME, _
Default:=rngCurrentRowShopOrder.Address, Type:=8)
On Error GoTo MoveShopOrder_Error
If rngShopOrderToMove Is Nothing Then
MsgBox "Operation Cancelled"
GoTo ErrorExit
Else
Set rngShopOrderToMove = wksSheet.Cells(rngShopOrderToMove.Row, _
glSCHED_SO_COL)
End If

lucas
02-15-2010, 12:23 AM
When it cancels, are you able to select a range on the sheet?

wolverineb
02-15-2010, 12:25 AM
It doesn't cancel, exactly. It acts like it's working but then when you click on OK it cancels. So you can select a cell and click OK. It just acts like you clicked Cancel if there was any scrolling involved before that.

lucas
02-15-2010, 12:31 AM
Is there any code in the sheet module?

lucas
02-15-2010, 12:35 AM
Does this code behave the same way on the sheet?
Option Explicit
Sub selectRange()
Dim rng As Range
On Error Resume Next
Set rng = Application.InputBox("Select the target range with the mouse", Type:=8)
If rng Is Nothing Then Exit Sub
On Error GoTo 0
rng.Value = 2
End Sub

Paul_Hossler
02-15-2010, 06:06 AM
If I add the line to Set rngCurrentRowShopOrder = something, .Input seems to work as expected



Option Explicit

Const sMessage1 As String = "Test"
Const gsAPPNAME As String = "Test App"
Const glSCHED_SO_COL As Long = 2

Sub drv()
Dim rngCurrentRowShopOrder As Range
Dim rngShopOrderToMove As Range
Dim wksSheet As Worksheet

Set wksSheet = ActiveSheet

'added line - no .Address if rngCurrentRowShopOrder not Set
Set rngCurrentRowShopOrder = wksSheet.Rows(1)

On Error Resume Next
Set rngShopOrderToMove = Application.InputBox(sMessage1, gsAPPNAME, _
Default:=rngCurrentRowShopOrder.Address, Type:=8)
On Error GoTo MoveShopOrder_Error
If rngShopOrderToMove Is Nothing Then
MsgBox "Operation Cancelled"
GoTo ErrorExit
Else
Set rngShopOrderToMove = wksSheet.Cells(rngShopOrderToMove.Row, _
glSCHED_SO_COL)
End If

MoveShopOrder_Error:
ErrorExit:
End Sub


Paul