Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    Moorpark, CA
    Posts
    104

    Cool Unanswered: VBA problems with MsgBox and CmdButtons

    Hi -

    I have two problems. First, I have created a MsgBox for when a command button is clicked on a form. The on click of the button enables and unlocks a few fields on the form. The msgbox has an OK button and a cancel button. I would like the OK to run the code for the current record only (i.e. unlock the fields for the current record only) and I would like the Cancel to do nothing. Is there a way to write that in to the code?

    Secondly, there is another command button that opens a new record and unlocks the fields. It works great except it unlocks the fields for ALL the records and not just the new one. I want it only to run the code for the current record. Is that possible?

    Please advise. If you need more info or clarification, please just let me know! =)

  2. #2
    Join Date
    Dec 2004
    Posts
    277

    As Far as THe Cancel Button

    I only put the code in for the OK button if its Cancel just don't do anything like this

    Dim Box As VbMsgBoxResult
    Box = ("Blah Blah Blah",vbOKCancel,"Yup")
    If Box = vbYes Then
    Do What ya gotta do
    End If

  3. #3
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    You can use the reponse to a message box in code:

    Code:
    Dim intReply as Integer
    intReply = MsgBox("SomeText",vbOkCancel,"Box Title")
    If intReply = vbOk Then
       'run some code
    End If
    vbOk is just a VB constant that contains a numerical value.
    Instead of using vbOkCancel as your button, you could use vbYesNo, etc
    See help on the MsgBox.
    Inspiration Through Fermentation

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Quote Originally Posted by Jennay
    ...
    Secondly, there is another command button that opens a new record and unlocks the fields. It works great except it unlocks the fields for ALL the records and not just the new one. I want it only to run the code for the current record. Is that possible?
    I'm guessing the code on the New Record button moves to a new record,
    and then does something like
    Me!txtField1.Locked = False
    Me!txtField2.Locked = False
    ...

    One way to handle that is to still have the button move the form to a new
    record, but use the form's OnCurrent event to determine which controls are locked/enabled.

    Code:
    Private Sub Form_Current()
      If Me.NewRecord Then
         Me.txtField1.Locked = False
         Me!txtField2.Locked = False
       Else
         Me.txtField1.Locked = True
         Me!txtField2.Locked = True
       End IF
    Inspiration Through Fermentation

  5. #5
    Join Date
    Nov 2003
    Location
    Moorpark, CA
    Posts
    104
    Great! I used everything recommended and it all works great! Thanks so much. I am posting a new problem, so I'd love for you to take a look!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •