在messageBox的答案後,我想讓用戶回到組合框'aceCount'。但是,它似乎完全跳過了這條線。在下面的代碼中,我有兩個消息框「代碼工作」和「聚焦後」;都顯示出來,所以我知道它正在讀取該區域的代碼,它只是從字面上忽略了setfocus作品。我已經閱讀了每篇文章,並嘗試了其他問題的多種解決方案,但無濟於事。它也不會在消息框之後的窗體上將焦點設置爲「任何」。我試着用文本框和組合框。MsgBox後,VBA忽略ComboBox的setfocus
編輯:它似乎是setfocus我需要的組合框,但然後執行到結束如果下面粗體和貫穿代碼。它不會給用戶重新提交的機會。
Private Sub SubmitButton_Click()
'Calls all necessary subs to perform required actions. If you add a sub, you will have to call it here if you want it to perform when you submit the form.
'If you have requested any number of HA Oracle servers, checks also if ACE and F5 are empty:
If Me.oracleCount.ListIndex > 0 Then
'If Ace and F5 are empty, MessageBox requesting review.
If aceCount.Value = 0 And F5Count.Value = 0 Then
If MsgBox("You have requested a HA Oracle server, but no Ace or F5. Do you need ACE or F5?", vbYesNo + vbQuestion, "ACE or F5?") = vbYes Then
'If chooses yes, goes back to form to allow user to input data
Cancel = True
MsgBox "code working"
UserForm1.aceCount.SelStart = 0
MsgBox "after focus"
'If chooses no, submits code as normal
Else
Call EnterData
Call HideSheets
Unload Me
**End If**
'If value in either Ace or F5, submits code as normal
ElseIf (Me.aceCount.Value <> 0 Or Me.F5Count.Value <> 0) Then
Call EnterData
Call HideSheets
Unload Me
End If
Else
End If
Call EnterData
Call HideSheets
Unload Me
末次
我沒有看到你在哪裏都是焦點設置到任何東西...... –
是的,你是正確的。在嘗試這麼多事情時,我認爲這條線被無意中刪除了。但是,即使代碼如下,仍然沒有關注。 「如果選擇是,返回到形成,以允許用戶輸入數據 取消=真 MSGBOX‘代碼工作’ ‘焦點後’ UserForm1.aceCount.SetFocus UserForm1.aceCount.SelStart = 0 MSGBOX」如果沒有選擇,正常提交代碼 – aoman49