Results 1 to 7 of 7
  1. #1
    raton is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2012
    Posts
    22

    conditional msgbox in a control


    i have bound data entry form. one field is textbox contain the primary key. if i type in the textbox then delete it and try to close it shows a msg
    but i want my custom msg with yes no field. if i press yes button then the cursor will go to the textbox and if i press the no button then the form will close. how can i do that. help

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    How are you closing form - command button or the X close?

    What is the message you get?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    raton is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2012
    Posts
    22
    x close
    the msg "the field (textbox name) cannot contain a null value bcs the required property for this field is true" yes no msgbox
    click yes
    access standard msgbox
    "access encountered problem when save the record do you want to close the database object anyway"

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Closing a form is one way an initiated record is committed to the table. The record was initiated when value entered entered the textbox, and because it is a required field, the record can't save until it has a value. Try the Undo method. In the form's Close event. http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

    If IsNull(Me.textboxname) Then
    If MsgBox("No primary key. Cancel record?", vbYesNo) = vbYes Then
    Me.Undo
    Else
    Cancel = True
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    raton is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2012
    Posts
    22
    Thanks June
    1. its almost working fine.
    your Code is ok
    but after form open when i typed something in the textbox and delete it and press the enter button then the msgbox shows
    if i press the yes button of msgbox, the textbox get focus after that i do not typed anything and press the enter then the msgbox
    is not shown and the cursor go to the next control though the textbox is null......................


    2. when i click the X button of the form
    i want a msg with yes no. if i click yes, form will close but if i press no
    the form won't close. how can i do that
    i am trying the code mentioned below but no condition of the msgbox is not working



    Private Sub Form_Close()
    If IsNull(Me.tblpid) Then
    If MsgBox("no primary key Typed." & vbCrLf & "Do You Want to Close?", vbQuestion + vbYesNo, "confirm") = vbYes Then
    Me.Undo
    Else
    Cancel = True
    DoCmd.CancelEvent
    End If
    End If
    End Sub

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I actually never used Close event. I normally disable the X close button and use command button to control closing. So my suggestion was a quick brainstorm last night. Now I have chance to test and not having success with Close event. I tried BeforeUpdate and it almost works. Can't get rid of the 'Can't save record at this time' warning message.
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.Text40) Then
        If MsgBox("Close", vbYesNo) = vbYes Then
            Me.Undo
            Cancel = True
        End If
    End If
    End Sub
    Annoying thing about Close and Unload events is they run even if you switch to Design view.

    This all reminds me why I disable the X close button.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    raton is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2012
    Posts
    22
    many many thanks, june
    for your genorus help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 03-14-2012, 08:32 PM
  2. Yes No msgbox
    By imintrouble in forum Access
    Replies: 3
    Last Post: 10-14-2011, 02:24 PM
  3. Caution MsgBox
    By rovman in forum Access
    Replies: 1
    Last Post: 10-02-2011, 05:40 PM
  4. Conditional Control Source
    By tylerg11 in forum Programming
    Replies: 4
    Last Post: 09-26-2011, 07:47 AM
  5. MsgBox
    By Mtyetti in forum Forms
    Replies: 4
    Last Post: 07-27-2011, 01:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums