Data Access Pages - adding command buttons & other functionality

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • beacon
    Contributor
    • Aug 2007
    • 579

    Data Access Pages - adding command buttons & other functionality

    Hi everybody,

    I've searched and searched for the answers to these questions until I've turned blue in the face, so I finally decided to come here for some assistance.

    Here's the info I'm working with:
    MS Access 2003
    Call log database using data access pages
    One table called tblCRS_Data_Log
    Primary key is CallNo
    An assortment of other fields, including check, text, and combo boxes
    There are other tables that supply the info for the combo boxes

    I'm trying to make this functional for my least computer saavy employees. The main thing I'm trying to accomplish is to be able to add some similar functionality to the data access pages as I would to a regular form.

    In particular, I have a separate date field and time field. I would like to add a today and yesterday command button to input the date for the date field and a current command button to input the current time. Those are the two most important aspects.

    The other thing I would like to accomplish, if possible, but not entirely necessary, is to be able to add functionality to a checkbox so that it will enable a text field and change the fore color of the corresponding label red when the value of the checkbox is true.

    I have some experience with javascript (in fact, I have a today and yesterday function written) and I've stumbled through a little vbscript before, but my problem is implementing it using the data access page. That is something that has completely thrown me for a loop.

    If you can help me with this, and the sooner the better, I would greatly appreciate it. Thanks in advance...
  • beacon
    Contributor
    • Aug 2007
    • 579

    #2
    I figured out the first part of my problem and I will post it here for anyone that might find it useful.

    To add a command button that will input the date into a text field, draw the command on your data access page (DAP) and then go to the Microsoft Script Editor. Change to "Script Only View" and open your "Document Outline" toolbar.

    Find the name of your command button in the "Document Outline" list and expand the sublist. Double click the "onclick" event and a new script tag will appear in the editor.

    For me, I just want to add a button for today's date and another button for yesterday's date. Here's what I typed in between the script tags:

    [code=vbscript]

    ''''''''''''''' ''''''''''''''' ''''''''''''''
    ' Today's date
    ''''''''''''''' ''''''''''''''' ''''''''''''''

    <SCRIPT language=vbscri pt event=onclick for=cmdToday>

    dim myDateT 'declare variable for the date to be stored

    myDateT = Date() 'set the variable equal to today's date

    DateField.value = myDateT 'make the textbox equal to the value stored in the variable

    </SCRIPT>

    ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
    ' Yesterday's date
    ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''

    <SCRIPT language=vbscri pt event=onclick for=cmdYesterda y>
    <!--

    dim myDateY 'declare variable for the date to be stored

    myDateY = Date()-1 'set the variable equal to yesterday's date

    DateField.value = myDateY 'make the textbox equal to the value stored in the variable

    -->
    </SCRIPT>

    [/code]

    Here's another script if you want to input a time in hh/mm AM/PM format (Thanks to http://www.ronshardwebapps.com for the code. Be sure to check out the site for complete details and further instruction):

    [code=vbscript]

    ''''''''''''''' ''''''''''''''' ''''''''''''
    ' Current time
    ''''''''''''''' ''''''''''''''' ''''''''''''

    <SCRIPT language=vbscri pt event=onclick for=cmdCurrent>
    <!--
    dim temp, myTime, myAMPM, myColon, myHour, myMinute

    temp = FormatDateTime( Time(), vbLongTime)

    myAMPM = Right(temp, 2)

    myColon = instr(1, temp, ":", vbBinaryCompare )
    if myColon = 2 then
    myHour = Left(temp, 1)
    myMinute = Mid(temp, 3, 2)
    else
    myHour = Left(temp, 2)
    myMinute = Mid(temp, 4, 2)
    end if

    myTime = myHour & ":" & myMinute & " " & myAMPM

    TimeField.value = myTime

    -->
    </SCRIPT>
    [/code]

    *************** *********
    Please Help !
    *************** *********

    I'm still having trouble with one part. I have a textbox that, when clicked, I want to be able to enable 2 other textboxes and change the label color red. If anyone can help me out with that I would really appreciate it.

    It's easy to do with VBA in Access, but these DAPs seem to be a different animal.

    Thanks,

    Comment

    • beacon
      Contributor
      • Aug 2007
      • 579

      #3
      Ok...my post can be closed. I finally got everything to work.

      If you want a label to be changed when the state of a checkbox is changed, you have to use the following:

      [code=vbscript]

      labelName.style .color = "red"

      [/code]

      Initially I was using the RGB(red, green, blue) function on the other side of the equal sign and when I entered (255,0,0) for red, for some reason, the color was changing to blue. Still can't figure that one out...maybe I needed to put it in quotes? Oh well, I'm good to go now...

      Comment

      Working...