i cant pass the value from table to textbox through dlookup

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rheigny
    New Member
    • Sep 2012
    • 9

    i cant pass the value from table to textbox through dlookup

    I dont know why I cant pass the value of AccountType (from TblAccount) to Me.txtWAccounTy pe(textbox from WithdrawView)

    pls help me.. here's my code

    Code:
     If IsNull(DLookup("[AccountId]", "TblAccount", "AccountId = '" & txtWAccountId & "'")) Then
     MsgBox "Account Number Doesn't Exist"
    
     Else
     Me.txtWAccounType.Value = DLookup("[AccountType]", "TblAccount", "AccountId = ' " & Forms![WithdrawView]![txtWAccountId] & "' ")
     MsgBox "Account Number Do Exist"
    
     End If
    my goal is to retrieve that AfterUpdate of AccountId. messagebox"Acco unt Number Do Exist" pop up so it means there is a value but why it doesn't appear in Me.txtWAccounTy pe.

    pls help.. thank you.
    Last edited by Meetee; Oct 10 '12, 12:52 PM. Reason: please use code tags <code/> around your code
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Something that I just noticed is that in line 5, it looks like you left out a T in Me.txtWAccounTy pe. Just a guess. If that fixes it, then you can ignore the rest of this post.

    Your DLookup should be like this:

    Code:
    DLookup("AccountID", "TblAccount", "AccountID =" & txtWAccountID)
    The name AccountID makes me think that the value is a number, in which case you don't want the ' surrounding it. Also, in line 5, I'm assuming that the active form is WithdrawView since in line 1 you left off the Forms!WithdrawV iew! before the control name. If I'm wrong, then you would need to add it back on to the code that I posted. Also in line 5, you don't need the .Value. All you need is
    Code:
    Me.txtWAccounType = ...

    Comment

    • Rheigny
      New Member
      • Sep 2012
      • 9

      #3
      Thank you. I did your suggestion but the textbox value is still null. I didn't get any error message and the messagebox"Acco unt Number Do Exist" only proves that there is a value found but why it doesn't appear on my textbox? anyway AccountID is a string
      example : 20091S

      Thank you so much..

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        Lets see if I can narrow down where the problem is. Above the code that you posted, put in the following:

        Code:
        Dim strResult as String
        strResult = DLookup("AccountID", "TblAccount", "AccountID =" & txtWAccountID)
        Then, in line 5 of what you posted, replace the DLookup... with strResult.

        Now click in the gray area next to that line of code (while in the VBA editor). A red dot should appear. Now do whatever is required to make your code execute. The code will stop at the line with the red dot. Now press Ctrl+G to make the Immediate window appear. Type into the immediate window
        Code:
        ? strResult
        What do you get?

        Comment

        • Rheigny
          New Member
          • Sep 2012
          • 9

          #5
          Sir Do you have other suggestion on how can i get table field value and put it in the textbox (as a part of searching the record) where the values to be inserted on the textbox depends upon the AccountID?
          thank you so much..

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3664

            #6
            Rheigny,

            Are txtWAccountId and Forms![WithdrawView]![txtWAccountId] supposed to be the same control on the same form? If so, then your code could look like this:

            Code:
            If IsNull(DLookup("[AccountId]", "TblAccount", "AccountId = '" & Me.txtWAccountId & "'")) Then 
                MsgBox "Account Number Doesn't Exist" 
            
            Else 
                Me.txtWAccounType.Value = DLookup("[AccountType]", "TblAccount", "AccountId = ' " & Me.txtWAccountId & "'")
                MsgBox "Account Number Do Exist" 
            End If
            Syntax for references to forms must be pretty exact....

            Comment

            • Rheigny
              New Member
              • Sep 2012
              • 9

              #7
              There's an error now after i did your suggestion its
              Run-time error "3075":
              Syntax error (missing operator) in query expression 'AccountID = 20091S'

              and highlight this

              Code:
              strResult = DLookup("AccountID", "TblAccount", "AccountID =" & txtWAccountId)
              Last edited by zmbd; Oct 10 '12, 08:34 PM. Reason: Please format VBA, HTML, XML, SQL, etc... using the <CODE/> button.

              Comment

              • Rheigny
                New Member
                • Sep 2012
                • 9

                #8
                ? strResult
                20091S

                Here's what I get from immediate window sir.

                Comment

                • twinnyfo
                  Recognized Expert Moderator Specialist
                  • Nov 2011
                  • 3664

                  #9
                  You forgot the single quote to designate a String...

                  Code:
                  strResult = DLookup("AccountID", "TblAccount", "AccountID =[B][U]'[/U][/B]" & txtWAccountId [B][U]& "'"[/U][/B])

                  Comment

                  • Rheigny
                    New Member
                    • Sep 2012
                    • 9

                    #10
                    Wow sir It's working! Thank you so much!

                    Comment

                    • twinnyfo
                      Recognized Expert Moderator Specialist
                      • Nov 2011
                      • 3664

                      #11
                      My pleasure! Glad we could assist you today!

                      Comment

                      • Rheigny
                        New Member
                        • Sep 2012
                        • 9

                        #12
                        Thank you so much again!

                        Comment

                        Working...