Results 1 to 13 of 13
  1. #1
    2410Davie is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2016
    Posts
    14

    Auto Date when checkbox ticked


    Hi Guys/Girls

    I am building a database and I have a checkbox called 'Issued' and I want this to insert the current date into the field 'Issued Date' when ticked and to remove it when not ticked, I have looked on here and online and tried everything I have found but none work......this is what I have just now.

    Private Sub Issued_AfterUpdate()
    If Me.Issued = -1 Then
    Me.Issued_Date = Now()
    Else
    Me.Issued_Date = Null
    Me.Issued_By = Null
    Me.Issued_To = Null
    End Sub

    The reason I also have Else Me.Issued_By = Null and Me.Issued_To = Null is because I want these fields also to be black when its unticked.

    Any help would be great thanks

    Davie

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    You need an End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    just think, you was almost there. change your if statement to
    Code:
    if(me.issued)=-1 then

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by vicsaccess View Post
    just think, you was almost there. change your if statement to
    Code:
    if(me.issued)=-1 then
    Works for me without the added parenthesis. Why do you think they are needed.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    2410Davie is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2016
    Posts
    14
    Quote Originally Posted by vicsaccess View Post
    just think, you was almost there. change your if statement to
    Code:
    if(me.issued)=-1 then
    I changed it to this but still nothing?

    Private Sub Issued_AfterUpdate()
    If (Me.Issued) = -1 Then
    Me.Issued_Date = Now()
    Else
    Me.Issued_Date = Null
    Me.Issued_By = Null
    Me.Issued_To = Null
    End Sub

  6. #6
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    but you still don't have the end if that Bob suggested. Sorry Bob, i have always used parenthesis, seems like when i don't i get an error.
    Code:
    if me.issued=-1 then
    me.issued_date=now()
    else
    me.issued_date=null
    end if

  7. #7
    2410Davie is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2016
    Posts
    14
    Quote Originally Posted by vicsaccess View Post
    but you still don't have the end if that Bob suggested. Sorry Bob, i have always used parenthesis, seems like when i don't i get an error.
    Code:
    if me.issued=-1 then
    me.issued_date=now()
    else
    me.issued_date=null
    end if
    I have exactly that above like this

    Private Sub Issued_AfterUpdate()
    If Me.Issued = -1 Then
    Me.Issued_Date = Now()
    Else
    Me.Issued_Date = Null
    End If

    still doesnt update the issued_date field with anything

  8. #8
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    testdate.zip
    see if this is any different from what you have. this one works for me.

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by vicsaccess View Post
    but you still don't have the end if that Bob suggested. Sorry Bob, i have always used parenthesis, seems like when i don't i get an error.
    Code:
    if me.issued=-1 then
    me.issued_date=now()
    else
    me.issued_date=null
    end if
    Does your code actually get fired and run
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  10. #10
    2410Davie is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2016
    Posts
    14
    Quote Originally Posted by Bob Fitz View Post
    Does your code actually get fired and run
    Im a newbie so how would i know this?

  11. #11
    2410Davie is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2016
    Posts
    14
    Quote Originally Posted by vicsaccess View Post
    testdate.zip
    see if this is any different from what you have. this one works for me.
    It wont let me open this it says unrecognised file system or something

  12. #12
    2410Davie is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2016
    Posts
    14
    I fixed it, i noticed at the top with an option to turn it on.....it now works great...To think i have been at this for hours lol

    Thanks for all the help guys.

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by 2410Davie View Post
    Im a newbie so how would i know this?
    See: http://www.techonthenet.com/access/t...ug/debug02.php
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Insert comment if checkbox is ticked
    By Nokoff in forum Access
    Replies: 28
    Last Post: 07-16-2015, 05:12 AM
  2. Replies: 6
    Last Post: 05-16-2014, 07:26 AM
  3. Replies: 4
    Last Post: 06-24-2013, 03:36 AM
  4. If Checkbox is ticked, Data Must be entered
    By DTK0902 in forum Access
    Replies: 8
    Last Post: 12-01-2012, 04:32 PM
  5. Open report if checkbox is ticked
    By Patience in forum Reports
    Replies: 3
    Last Post: 06-23-2010, 08:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums