if the component value is blank then it shld show current date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syedshaffee
    New Member
    • Jan 2012
    • 91

    if the component value is blank then it shld show current date

    Hey People

    please answer my question asked above...
    Code:
    I am having a report in access where the field is date type so i require this field to show current date if value is blank otherwise record source value.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    syedshaffee,

    I would add a small sub to the On Current event of the report that checks the value of the Date Value you are interested in. If it is null (no date) then update this control to the current date:

    Code:
    Private Sub Report_Current()
        If IsNull(Me.txtDate) Then Me.txtDate = Date
    End Sub
    Hope this helps!

    Comment

    • syedshaffee
      New Member
      • Jan 2012
      • 91

      #3
      twinnyfo,
      The Component has a control source buddy 'll it allow me to do the same

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3662

        #4
        If the report does not allow you to update the text box, add an unbound text box. Then, check the value of the underlying data and update the unbound text box to the date stored or the the current date, depending on what is in the table.

        Comment

        • syedshaffee
          New Member
          • Jan 2012
          • 91

          #5
          twinnyfo,
          Thanx, man you are a life saver thanx a million

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3662

            #6
            Glad I could help. If you would be so pleasant as to select my response as the best answer....

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              You can do this in your underlying query by using a calculated field. Use the IIF to determine if the data is there or not and either return the field value or the formatted date. Use this calculated field as the record source for your your control.

              Here's a simple example...
              Table3 has two numeric fields [F1] and [F2].
              [F1] is required and primary key
              [F2] is allowed to be null.
              You could make them date fields.
              A simple select query that returns all of the records for [F1][F2] and calculated field [z_return0]; however, if [F2] is null then it returns a numeric zero in the field [z_return0]

              Code:
              SELECT  Table3.f1, 
              	Table3.f2, 
              	IIf(IsNull([f2]),0,[f2]) AS z_return0
              FROM Table3;
              You can return a formatted date or what ever...

              No VBA code to write and will work if the code is disabled.

              -z


              -z

              Comment

              Working...