Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox okonly

Status
Not open for further replies.

handlebarry

Technical User
Dec 21, 2004
118
GB
My message box is a vbOkOnly style. All I want to is close a form when the user clicks on ok.

I'm familar with message boxes in vb but I just can't seem to track down this answer! (usually use select case vbYes,vbNo etc)

thanks in advance
 
the message box is part of an if statement, so I think the form would close even when not required

here is what I have as a back up. What I really want is for "vbYes" to occur when clicking on ok (does that make sense?)

Private Sub cmbONE_AfterUpdate()

Dim strMessage As String
Dim crlf As String
Dim Message
Dim Style
crlf = Chr$(13) & Chr$(10)
Style = vbYesNo
strMessage = "No Contracts for this Block" & crlf
strMessage = strMessage & "Search again?" & crlf

If Me.Frame93.Value = 3 Then DoCmd.OpenForm "frmContractBlocks"
If Forms!frmContractBlocks!sfrmBlockSearchContracts.Form.RecordsetClone.RecordCount = 0 Then Message = MsgBox(strMessage, Style)

Select Case Message
Case vbYes: DoCmd.Close acForm, "frmContractBlocks"
Case vbNo: DoCmd.Close acForm, "frmContractBlocks"
DoCmd.Close acForm, "frmcontractDetails"
End Select
 
Since you'll never get the vbNo event with just an OK button, why not:
Code:
Private Sub cmbONE_AfterUpdate()

    Dim strMessage As String
    strMessage = "No Contracts for this Block" & vbCrLf
    strMessage = strMessage & "Search again?" & vbCrLf
              
    If Me.Frame93.Value = 3 Then DoCmd.OpenForm "frmContractBlocks"
    If Forms!frmContractBlocks!sfrmBlockSearchContracts.Form.RecordsetClone.RecordCount = 0 Then MsgBox(strMessage)
    
    DoCmd.Close acForm, "frmContractBlocks"
End Sub

[pc2]
 
Oops, omission in my last post:
Code:
Private Sub cmbONE_AfterUpdate()

    Dim strMessage As String
    strMessage = "No Contracts for this Block" & vbCrLf
    strMessage = strMessage & "Search again?" & vbCrLf
              
    If Me.Frame93.Value = 3 Then DoCmd.OpenForm "frmContractBlocks"
    If Forms!frmContractBlocks!sfrmBlockSearchContracts.Form.RecordsetClone.RecordCount = 0 Then 
        MsgBox(strMessage)
        DoCmd.Close acForm, "frmContractBlocks"
    Else
        ' Do something with the found record
    End If
End Sub

[pc2] [URL unfurl="true"]http://www22.brinkster.com/accessory/[/URL]
 
that gives me a type mismatch but it is the correct method -I think I should move the code to the form that opens

thanks for the help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top