VBA for form open

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sandhya1988
    New Member
    • Oct 2014
    • 30

    VBA for form open

    Hello friends, please can anyone solve my issue

    I have used VBA on TrNo filed as per shown on Code Tag for below following forms open purpose so it is not working properly only open BT_DepositEntry Modify form otherwise not working. I think just need to change VBA code so please replay how to give a VBA in this case. I have attached the dB and Screenshot with Explanation.

    Forms:
    BT_DepositEntry Modify
    BT_WithdrawEntr yModify

    Code:
    Private Sub TrNo_Click()
    On Error GoTo ErrorHandler
     If Left(Me!ID, 1) <> "D" Then
        DoCmd.OpenForm "BT_DepositEntryModify", acNormal, "BT_DepQry", "TrNo= " & Val(Me!TrNo)
     Else
        DoCmd.OpenForm "BT_WithdrawEntryModify", acNormal, "BT_WDrawQry", "TrNo= " & Val(Me!TrNo)
     End If
    ErrorHandler:
    End Sub
    Thanks,
    Sandhya.
    Attached Files
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    You don't tell what Me!ID is or the values found there. I can't open zip files at work. Are you getting errors? Please explain.

    Comment

    • Sandhya1988
      New Member
      • Oct 2014
      • 30

      #3
      Thanks for replay
      There is no error but in the VBA code two type’s conditions shown for form opening so 1st one is BT_DepositEntry Modify form this is working well.
      But 2nd one is BT_WithdrawEntr yModify form this form is can’t open when I click on TrNo as per screenshot and in this form place also open 1st one BT_DepositEntry Modify form.
      So I need to open 2nd form also BT_WithdrawEntr yModify form as per TrNo field require.

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3653

        #4
        Yes, but your code is dependent upon ME.ID, and since you haven't shared what values are found in that fields, TrNo is immaterial.

        Comment

        • Sandhya1988
          New Member
          • Oct 2014
          • 30

          #5
          Yes, I’m not sure that code is correct or wrong just i tried. Forms & Query fields as per below following details

          Form: BT_DepositEntry Modify (Query: BT_DepQry also same fileds)
          Fields:
          ID
          TrNo
          TranDate
          Particulars
          ChqTNo
          ChqPassedReject ed
          Deposits

          Form: BT_WithdrawEntr yModify (Query: BT_WDrawQry also same fileds)
          Fields:
          ID
          TrNo
          TranDate
          Particulars
          ChqTNo
          ChqPassedReject ed
          Deposits
          Withdraws

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3653

            #6
            What are the values that you will find in the ID field?

            Since your If...Then statement is checking that value, but it never opens the other form, this is where you must start your troubleshooting--which is why I keep asking about it.....

            Comment

            • Sandhya1988
              New Member
              • Oct 2014
              • 30

              #7
              ID filed value is AutoNumber & format is start with (D1, D2, D3 )
              TrNo filed Value is Serial number & format is start with (1,2,3)

              Comment

              • twinnyfo
                Recognized Expert Moderator Specialist
                • Nov 2011
                • 3653

                #8
                Because of Line 3:

                Code:
                If Left(Me!ID, 1) <> "D" Then
                And the formate of ID is always "Dx", you will ALWAYS open the first form--no matter what. This is where your problem is.

                Comment

                • Sandhya1988
                  New Member
                  • Oct 2014
                  • 30

                  #9
                  DoCmd.OpenForm "BT_WithdrawEnt ryModify", acNormal, "BT_WDrawQr y", "TrNo= " & Val(Me!TrNo)

                  this is the problem so any chance to changes VBA ? for second form also need to be open ?

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    The problem isn't the code to open the form. The problem is the code that decides which form to open.

                    Comment

                    • Sandhya1988
                      New Member
                      • Oct 2014
                      • 30

                      #11
                      VBA for form open

                      Attached the as per screenshot Bank Transaction Details form in the last 2 rows records is Form: BT_WithdrawEntr yModify & first 2 rows records is Form: BT_DepositEntry Modify
                      Both of differences is Withdraws Rs. & Deposits Rs. field amounts so in this case I need to form open If Amount is Withdraws Rs. filed side then will be open the form: BT_WithdrawEntr yModify Or Deposits Rs. field side then will be open the form: BT_DepositEntry Modify that’s way am using VBA on TrNo filed but can't workout.
                      Attached Files

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        The problem is that the TrNo has nothing to identify whether or not that row is a deposit or a withdrawal. And neither does the ID field.

                        Comment

                        • Sandhya1988
                          New Member
                          • Oct 2014
                          • 30

                          #13
                          Thanks for suggestions.. I will change the structure and after will try to other sources.

                          Comment

                          Working...