set focus on TextBox.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • billa856
    New Member
    • Nov 2007
    • 101

    set focus on TextBox.

    Hi,
    My Project is in MS Access 2002.
    In that I have one form which I am using for data entry.
    Now in that I have some TextBoxes like
    PalletNo,TotalP allets,ItemNo,L ONo,PONo,BatchN o,LotNo,Cartons ,PcsPerCarton etc.
    Now when person scan a barcode from paper it will automatically enter Number(Like 24914) in first PalletNo TextBox.
    In the AfterUpdate event of PalletNo TextBox I put some code so it will search the values of ItemNo,LONo,PON o,BatchNo,LotNo ,Cartons,PcsPer Carton etc and automatically put it in TextBoxes.and TotalPallets=1
    Now again when person scan new barcode it will do the same thing as above for second PalletNo(Like 24915).But There is one more criteria that if ItemNo,LONo,PON o,BatchNo,LotNo ,Cartons,PcsPer Carton are same as it is for first PalletNo then it will TotalPallets=To talPallets+1.an d PalletNo=FirstP alletNo;SecondP alletNo(its value like this 24914;24915) and it will null the all details for second PalletNo so I can use it again.
    Now when it null the values i put one more line
    Me.PalletNo2.Se tFocus

    But its not working it will go to the next TabStop.So I have to again click on previous PalletNo and scan Barcode over There.
    My Form is Unbound because I didn't Use Form Wizard to creat it.
    Is this possible bcz of that its not working?

    One more thing I want to know that ,
    I put code in AfterUpdate event of PalletNo TextBox.Now after scaning the Barcode I have to press Tab or Click on another TextBox then it will enter the value Automatically in respective TextBoxes.Is that possible as soon as i scan the Barcode and it will enter the value in PalletNo TextBox then it will automatically search for Data as per search criteria and automatically add data in TextBoxes and cursor go to the next PalletNo.So that if I scan the First barcode then it will enter data and go to the next barcode and I have to only scan another barcode.I don't have to press Tab or Click on another TextBox again and again.

    If u have any suggestion then plz give me.
  • MindBender77
    New Member
    • Jul 2007
    • 233

    #2
    OK, wow, you got alot going on here. First, you can use an IF statement in the OnExit event of a textbox to catch null values. Example:

    [code=vb]
    If isnull(TextBox1 ) = true then
    TextBox2 = "" 'Returns an empty textbox
    end if
    [/code]

    Lastly, you can use Dlookup to automatically populate all of you textboxes bases on a single barcode scan and no click or tabbing. On the OnExit event of your barcode textbox, you would do something like:
    [code=vb]
    Private Sub Autopopulate()
    Dim Pnum as integer

    Pnum = dlookup("[Field Name]", "YourTableName" ,"[Field Name] = Textbox2")
    Pnum = Textbox8
    End Sub
    [/code]

    I sugggest doing a little research on the above mentioned stratagies,
    Bender

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Because of a quirk in Access, you cannot directly set focus to a control from that control's AfterUpdate event. Instead, you have to set focus to another control then set control back to the control in question:

      Code:
      Private Sub PalletNo_AfterUpdate()
        Me.AnyOtherTextbox.SetFocus
        Me.PalletNo.SetFocus
      End Sub
      Linq ;0)>

      Comment

      • billa856
        New Member
        • Nov 2007
        • 101

        #4
        I used the same thing in my coding.

        The problem was that the text box I want to set focus to, already has the focus. Therefore, the command is not carried out. The way to handle this is to put a transparent command button immediately following the text box of interest in the tab order. Then a bit of code in its GotFocus event can set the focus back to the text box.

        And Now its working Properly.
        Thanks For Ur Replies.

        Comment

        • davedenson
          New Member
          • Dec 2011
          • 1

          #5
          Thanks. I've been agonizing over this problem for days.
          Dave Denson

          Comment

          Working...