setfocus doesnt work again,

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rockdc1981
    New Member
    • Apr 2007
    • 51

    setfocus doesnt work again,

    please help me with my code, any revisions is appreciated...


    Private Sub Combo42_LostFoc us()
    Dim Result
    Dim Msg
    Dim cr As String
    cr = Chr$(13)
    Result = Me.Combo42
    If IsNull(Result) = False Then
    End If
    If IsNull(Result) = True Then
    MsgBox "Pharma Record is Empty", vbOKCancel
    If True = vbOK Then
    Me.Combo42.SetF ocus ' i wanted the focus to get back on the combo if value is null
    Else
    End If
    End If
    End Sub
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    This is the Articles section. I am moving this to the Access forum.

    ADMIN

    Comment

    • cyberdwarf
      Recognized Expert New Member
      • Nov 2006
      • 218

      #3
      Try:-

      Code:
      If MsgBox("Pharma Record is Empty", vbOKCancel) = vbOK Then
      [b]	 Me.Combo42.SetFocus[/b]
      Else
      End If
      HTH
      Steve

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Cyberdwarf is correct, his solution will work.

        But wanted to point out why your code isn't working.

        If True = vbOK

        True is -1, vbOK is 0, they will never equal each other, meaning your code will never execute.

        Comment

        • rockdc1981
          New Member
          • Apr 2007
          • 51

          #5
          Mary so sory for posting it on the article, that was unintentional.. .anyway thanks for the help guys!more power

          Comment

          • rockdc1981
            New Member
            • Apr 2007
            • 51

            #6
            I made some revisions..my problem now is after Cancel, how will i close the form


            Private Sub Combo42_LostFoc us()

            Dim Result
            Result = Me.Combo42
            If IsNull(Result) = False Then
            End If
            If IsNull(Result) = True Then
            MsgBox " Pharma Record is Empty, Click Retry to Select Record or Cancel to Exit Form", vbRetryCancel
            If True = vbRetry Then
            Me.Command57.Se tFocus 'other field
            Me.Combo42.SetF ocus
            Else
            ' a command that will close the form, i tried docmd.close acform but its wrong...
            'Me.Command57.S etFocus 'other field
            'Me.Combo42.Set Focus
            End If

            End If
            End Sub

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              You are making the same mistake as before ...
              Code:
                   If True = vbRetry Then
              This will never be true. Firstly you haven't returned any value from the msgbox.

              The return values are as follows:

              vbOK = 1
              vbCanel = 2
              vbAbort = 3
              vbRetry = 4
              vbIgnore = 5
              vbYes = 6
              vbNo = 7

              Therefore your code should read ...
              Code:
              Dim rsp As Integer
              
              rsp = MsgBox ("Pharma Record is Empty,  Click Retry to Select Record or Cancel to Exit Form", vbRetryCancel)
                  If rsp = vbRetry Then ' or If rsp = 4 Then
              Mary

              Comment

              • rockdc1981
                New Member
                • Apr 2007
                • 51

                #8
                both of our code worked fine...

                Private Sub Combo42_LostFoc us()
                Dim Result
                Dim rsp As Integer
                Result = Me.Combo42
                If IsNull(Result) = False Then
                End If
                rsp = MsgBox("Pharma Record is Empty, Click Retry to Select Record or Cancel to Exit Form", vbRetryCancel)
                If rsp = vbRetry Then ' or If rsp = 4 Then
                'If IsNull(Result) = True Then
                'MsgBox "Select or Add Pharma Record to Continue", vbRetryCancel
                'If True = vbOK Then
                'DoCmd.Close acForm, "Pharma Query", acSaveNo
                Me.Command57.Se tFocus 'other field
                Me.Combo42.SetF ocus
                Else

                'Me.Command57.S etFocus 'other field
                'Me.Combo42.Set Focus

                'how will i close the form if cancel was chosen
                End If

                End Sub

                Comment

                • rockdc1981
                  New Member
                  • Apr 2007
                  • 51

                  #9
                  im gettin run time error 2585....action cant be carried out while processing a form or report event...

                  fisrt what does it mean
                  then waht should i do
                  then whats wrong

                  Comment

                  • rockdc1981
                    New Member
                    • Apr 2007
                    • 51

                    #10
                    for the benefit of other members who might want to use this heres the partially correct code...
                    Code:
                    Private Sub Combo42_LostFocus()
                    Dim Result
                    Dim rsp As Integer
                        Result = Me.Combo42
                    If IsNull(Result) = False Then
                    End If
                    If IsNull(Result) = True Then
                    rsp = MsgBox("Pharma Record is Empty", vbRetryCancel, "Empty Record")
                        If rsp = vbRetry Then ' or If rsp = 4 Then
                        Me.Command57.SetFocus 'other field
                        Me.Combo42.SetFocus
                        Else
                            Me.Refresh' i tried docmd.close but run time error occurs..
                        End If
                    End If
                    End Sub
                    do i get right now Mary...

                    Cheers!

                    Comment

                    Working...