Table search

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wayneyh
    New Member
    • Mar 2008
    • 67

    Table search

    Hello all

    Below is some code. This is the only way i know how to say what i want to happen. Could someone please re-code this so that it works please.


    Private Sub Postcode_LostFo cus()
    If Me.Postcode = Table!tblSales! PostcodeAnd Date >= Table!tblSales! DateOfVisit + 30 Then
    Me.lblOutstandi ng.Visible = True
    End If

    End Sub

    Kindest Regards

    Wayne
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    What are the fields and field types in your tblSales?
    You probably want to use DLookUp to get the values from the table.

    Comment

    • Wayneyh
      New Member
      • Mar 2008
      • 67

      #3
      The fields in tblsales are Postcode which is a text field and DateOfSale which is a date field

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        Let's start with some basics:
        Table=tblSales has 2 fields, Postcode and DateOfVisit
        Form=frmYourFor m should have 4 controls:
        txtPostcode TextBox - hidden, bound to Postcode - not good to name same as table field as this generates confusion.
        txtPostcodeEntr y - TextBox
        txtDateOfVisit TextBox - bound to DateOfVisit
        lblOutstanding - Label
        Code:
        Private Sub txtPostcodeEntry_LostFocus()
        If Me.txtPostcodeEntry = Me.txtPostcode And Date >= Me.txtDateOfVisit + 30 Then
        Me.lblOutstanding.Visible = True
        Else
        Me.lblOutstanding.Visible = False
        End If
        End Sub
        Me.txtDateOfVis it + 30 might be better as DateAdd("m",1,M e.txtDateOfVisi t)

        Comment

        • Wayneyh
          New Member
          • Mar 2008
          • 67

          #5
          Thanks for your input

          Wayne

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            While we're on basics, this kind of code is better being placed in the textbox AfterUpdate event, rather than its LostFocus event.

            The AfterUpdate event fires if a blank textbox has had data entered, or if the data has been edited. This is what you're trying to do.

            The LostFocus event fires every time you tab thru the field, even if nothing changes, which is a waste of processing time.

            For this type of formatting, you also need to include the code in the Form_Current event, so that as you move from record to record, the lblOutstanding label appears or is invisible, as is appropriate.

            Linq ;0)>

            .

            Comment

            Working...