Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Location
    Guelph, Canada
    Posts
    39

    Unanswered: Check box VB code

    I have a form with several command buttons.
    One button has the following VB code:

    ====================================
    Private Sub DetList_Click()
    On Error GoTo Err_DetList_Click

    Dim stDocName As String

    stDocName = "DETENTION LIST"
    DoCmd.OpenReport stDocName, acPreview

    Exit_DetList_Click:
    Exit Sub

    Err_DetList_Click:
    MsgBox Err.Description
    Resume Exit_DetList_Click

    End Sub
    =====================================

    I'd like to add code so that with the same click on this button, a
    check box is checked off. The check box name is check11.

    I also have a second command button that runs an append query with the following code:
    ===================================
    Private Sub PenaltyDet_Click()

    Dim stDocName As String

    stDocName = "Add Extra Det"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

    End Sub
    =====================================

    I'd like to add code so that with the same click on this second button, a
    check box is checked off *if the append was completed*. The check box name is check15.

    And finally, I'd like to have the checks automatically removed from the check boxes at the beginning of the next day.

    Instructions on how to accomplish this would be greatly appreciated.

    Thanks in advance! Eric

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    if you are tlaking about the current form:

    Private Sub DetList_Click()
    On Error GoTo Err_DetList_Click


    check11.value = false


    Dim stDocName As String

    stDocName = "DETENTION LIST"
    DoCmd.OpenReport stDocName, acPreview

    Exit_DetList_Click:
    Exit Sub

    Err_DetList_Click:
    MsgBox Err.Description
    Resume Exit_DetList_Click

    End Sub


    or, more expilict:
    Me!check11.value = false

    or, explicit and applicable to any form, not just the current form:
    forms!nameOfYourForm.check11.value = false


    for the second part, use a similar on error structure as the first part:

    Private Sub PenaltyDet_Click()
    on error goto err_PenaltyDet_Click

    Dim stDocName As String

    stDocName = "Add Extra Det"
    DoCmd.OpenQuery stDocName, acNormal, acEdit


    check11.value = False 'the happy exit
    exit_PenaltyDet_click:
    exit sub
    err_PenaltyDet_Click:
    check11.value = True 'the unhappy exit
    msgbox err.description
    resume exit_PenaltyDet_Click


    End Sub


    Last part: please define the beginning of the next day... is this at user logon, or ????


    izy

  3. #3
    Join Date
    Jan 2003
    Location
    Guelph, Canada
    Posts
    39
    Hi Izy,

    Thanks very much for your reply and help!


    Last part: please define the beginning of the next day... is this at user logon, or ????

    Sorry about that. In our case the beginning of the next day would be after midnight or say, 1:00 am. User logon would not be good because the admin/users could easily log off sometime during the day and then logon again later in the afternoon.

    Thanks! Eric

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    hi eric

    access has a millisecond timer but it would be sledgehammer vs nut to have this running all the time checking for midnight.

    simplest is to set up a separate application that links to any of your main tables that are needed for your midnight job. this app needs a single form that opens when the app starts. the form has all the code for your midnight job in the form_load event. set this app to start each midnight using the windows scheduler whizmo.

    you can add refinement... schedule your new app to run every hour to guard against network downs and:
    create a table myTable containing a single field: JobRan as Date. after you have created the table, open it just once and add a single record with a date sometime in the past (e.g. 1/1/1990).

    private sub form_load()
    on error goto err_form_load
    dim dabs as dao.database
    dim recs as dao.recordset
    set dabs = currentdb
    set recs = dabs.openrecordset("select * from myTable")
    recs.movefirst
    if clng(now()) > clng(recs!jobran) then
    'your job has not run today
    'put your one-time job code here
    'and after your code has sucessfully run:
    recs.edit
    recs!jobran = now()
    recs.update
    else
    'the job has already run today: do nothing
    endif
    exit_form_load:
    set recs = nothing
    set dabs = nothing
    docmd.quit
    exit sub
    err_form_load:
    'do something intelligent... a msgbox is not intelligent in
    'a run-alone application, but is helpful for development
    msgbox err.description, vbcritical, "Error running one-time job"
    resume exit_form_load
    end sub


    more refinement:
    use recs.movelast (instead of recs.movefirst)
    use recs.addnew (instead of recs.edit)
    ...and myTable now logs each successful run of the one-time job


    izy
    Last edited by izyrider; 01-27-03 at 04:42.

  5. #5
    Join Date
    Jan 2003
    Location
    Guelph, Canada
    Posts
    39
    Hi Izy,

    Thanks very much for your detailed reply!
    I will study it carefully and see if I can set it up right for my db.

    Thanks again,

    Eric

Posting Permissions

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