By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Data Access Pages - adding command buttons & other functionality

beacon
100+
P: 579
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...
Jul 29 '08 #1
Share this Question
Share on Google+
2 Replies


beacon
100+
P: 579
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ''''''''''''''''''''''''''''''''''''''''''''
  3. ' Today's date
  4. ''''''''''''''''''''''''''''''''''''''''''''
  5.  
  6. <SCRIPT language=vbscript event=onclick for=cmdToday>
  7.  
  8.     dim myDateT                    'declare variable for the date to be stored
  9.  
  10.     myDateT = Date()            'set the variable equal to today's date
  11.  
  12.     DateField.value = myDateT    'make the textbox equal to the value stored in the variable
  13.  
  14. </SCRIPT>
  15.  
  16. '''''''''''''''''''''''''''''''''''''''''''''''''''''''
  17. ' Yesterday's date
  18. '''''''''''''''''''''''''''''''''''''''''''''''''''''''
  19.  
  20. <SCRIPT language=vbscript event=onclick for=cmdYesterday>
  21. <!--
  22.  
  23.     dim myDateY                    'declare variable for the date to be stored
  24.  
  25.     myDateY = Date()-1            'set the variable equal to yesterday's date
  26.  
  27.     DateField.value = myDateY    'make the textbox equal to the value stored in the variable
  28.  
  29. -->
  30. </SCRIPT>
  31.  
  32.  
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):

Expand|Select|Wrap|Line Numbers
  1.  
  2. ''''''''''''''''''''''''''''''''''''''''''
  3. ' Current time
  4. ''''''''''''''''''''''''''''''''''''''''''
  5.  
  6. <SCRIPT language=vbscript event=onclick for=cmdCurrent>
  7. <!--
  8.                 dim temp, myTime, myAMPM, myColon, myHour, myMinute
  9.  
  10.     temp = FormatDateTime(Time(), vbLongTime)
  11.  
  12.     myAMPM = Right(temp, 2)
  13.  
  14.     myColon = instr(1, temp, ":", vbBinaryCompare)
  15.     if myColon = 2 then
  16.         myHour = Left(temp, 1)
  17.         myMinute = Mid(temp, 3, 2)
  18.     else
  19.         myHour = Left(temp, 2)
  20.         myMinute = Mid(temp, 4, 2)
  21.     end if
  22.  
  23.     myTime = myHour & ":" & myMinute & " " & myAMPM
  24.  
  25.     TimeField.value = myTime
  26.  
  27. -->
  28. </SCRIPT>
  29.  
************************
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,
Jul 30 '08 #2

beacon
100+
P: 579
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. labelName.style.color = "red"
  3.  
  4.  
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...
Jul 30 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.