Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2014
    Posts
    6

    Unanswered: Populating a column with a Single form field Value

    Hi pals, I have a form containing a field Pdate. I would like to populate a column "PrintDate" in the Emp_table table with the same value at Pdate.
    I have tried
    1.
    Private Sub txtPdate_AfterUpdate()
    Me.txtPdate.Value = PrintDate
    End Sub
    2.
    Private Sub txtPdate_AfterUpdate()
    strSQL = "UPDATE Employee_table SET [PrintDate] = Me.txtPdate.Value
    End Sub

    3.
    Private Sub txtPdate_AfterUpdate()
    PrintDate = Lookup(txtPrintDate.Value)"
    End Sub

    I have used the AfterUpdate() because the Pdate field is populated via three combo boxes day, month and year. Your help will greatly be appreciated.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Some things are missing:
    Code:
    Private Sub txtPdate_AfterUpdate()
        strSQL = "UPDATE Employee_table SET PrintDate = #" & Format( Me.txtPdate.Value, "yyyy-mm-dd") & "#"
        Currentdb.Execute strSQL, dbFailOnError
    End Sub
    Moreover, you'll probably need to specify a criteria (WHERE...): as it is, the query will update all rows in [Employee_table].
    Have a nice day!

  3. #3
    Join Date
    Sep 2014
    Posts
    6

    Populating a column with a Single form field value

    Quote Originally Posted by Sinndho View Post
    Some things are missing:
    Code:
    Private Sub txtPdate_AfterUpdate()
        strSQL = "UPDATE Employee_table SET PrintDate = #" & Format( Me.txtPdate.Value, "yyyy-mm-dd") & "#"
        Currentdb.Execute strSQL, dbFailOnError
    End Sub
    Moreover, you'll probably need to specify a criteria (WHERE...): as it is, the query will update all rows in [Employee_table].
    ******
    Thanks Sinndho for your help though still not working. Is there anything I am missing out?

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    "still not working" dos not help to solve anything. What does not work? Is there an error message when the code is executed? Does the code yields an unexpected result? Is the code executed at all? At first sight, I can imagine an error if the column [PrintDate] is not defined as of Date/Time data type. Apart from that, you'll need to supply more precise information about the problem.
    Have a nice day!

  5. #5
    Join Date
    Sep 2014
    Posts
    6
    Quote Originally Posted by Sinndho View Post
    "still not working" dos not help to solve anything. What does not work? Is there an error message when the code is executed? Does the code yields an unexpected result? Is the code executed at all? At first sight, I can imagine an error if the column [PrintDate] is not defined as of Date/Time data type. Apart from that, you'll need to supply more precise information about the problem.
    Thanks again Sinndho for your help. When I made the changes nothing happened, no error, no output. But then I got it sorted. I created an update query that is executed on button press once the Pdate field has been updated. It's working

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •