Hi Perry,
Sheesh! Ok, I was a newbie once too, and not too long ago, so I
understand... :)
I'm by no means an "exburp", but OK ... are you ready for Access97 "Coding
101"?
You've got to understand that you're about to explore VBA programming ...
the "true power" of Access.
============================ Stage One ========================
1.) Go the Database Window
2.) Click on the "Modules" tab
3.) Click [New]
4.) A code window titled "Module 1" will appear and will contain the
following text by default:
Option Compare Database
Option Explicit
5.) Copy all of the code below, position the cursor on the line following
the default text, and paste my code into that code window:
Global varDate 'This is in the module's main declaration area
Public Function GetDate()
'-----------------------------------------------------------
'Call this function from a date-formatted control on any form...
' eg:
''''Private Sub BegDate_DblClick(Cancel As Integer)
''''GetDate
''''Me![BegDate] = varDate
''''End Sub
'-----------------------------------------------------------
If Not IsLoaded("dlgCalendar") Then
DoCmd.OpenForm "dlgCalendar", , , , , acDialog
End If
'Because the calendar form is Modal, it retains the focus
'until closed.
'This allows the global variable "varDate" to be set/changed
'as long as the Calendar form remains open.
'Then, after the Calendar form is closed the "calling form's"
'code resumes and inserts the value of the varDate variable into the
'calling form's control.
End Function
************************************************** ***********
6.) You'll notice right away that the active code is mostly colored black,
and that lines preceded by an apostophe ( ' ) are intended as comments and
are green in color. Red is bad... that means you have syntax errors,or
commands that Access doesn't understand. (Hopefully you wont see any red
here.)
7.) On the menu bar, Debug/Compile Loaded Modules
8.) File / Save. Access will prompt you for a name for your new module. I'd
suggest naming it something meaningful like "modGetDate"
OK, that's one module down, and one more to go...
9.) Create another new module as in steps 1 to 4 above.
10.) Copy and paste the IsLoaded() function --- below --- into this second
module, as in step 5 :
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet
view.
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
11.) Repeat steps 7 & 8 as above.
============================= Stage Two ============================
12.) Assuming that you have already created an unbound form named
"dlgCalendar" (if not do so now.)
that contains the following controls:
a calendar control named "MyCal"
a command button named "cmdOK" with the caption "OK"
a label (name is not important) with the caption:
Select a Date from the calendar. <[ctrl] + [Enter]>
When finished click the OK button
13.) View / Code
14.) If this is a 'virgin' form, you'll be greeted with the now familiar
default text:
Option Compare Database
Option Explicit
15.) Copy and paste (you know the drill by now) this code into the
appropriate place.
Private Sub cmdOK_Click()
varDate = Me.MyCal
DoCmd.Close
End Sub
Private Sub Form_Open(Cancel As Integer)
varDate = Me.MyCal
End Sub
Private Sub MyCal_AfterUpdate()
varDate = Me.MyCal
End Sub
16.) Debug / Compile, and close the code window... save the form. You can
dress this form up a little too, while you're at it. You wont need scroll
bars, record selectors, navigation buttons, etc as this is an unbound form.
You can set things like a dialog-style border, Auto-center, and more for a
polished look.
Be sure to save and close the form again after.
============================= Stage Three ============================
17.) Open the form (in design view) that contains the textbox control that
you want to insert the date into. I have no idea what you are calling that
textbox control, so you have to modify the "YourControl" references below to
match YOUR actual control name.
18.) Select YourControl. Open the property sheet if it isn't already open.
19.) click on the "Event" tab.
20.) Choose an event that you would like this action to take place... I like
"On Dbl Click"
21.) Click on the "down-arrow" to the right of this event, and select
"[Event Procedure]"
22.) Click on the ellipse (...) to invoke the code editor, which opens the
code window and creates a place-holder for your event which should look like
this:
(And HEY.. there's that default text again!)
Option Compare Database
Option Explicit
Private Sub YourControl_DblClick(Cancel As Integer)
End Sub
23.) You need to copy and paste this into that event place-holder....
GetDate
Me![YourControl] = varDate
so that it now looks like:
Private Sub YourControl_DblClick(Cancel As Integer)
GetDate
Me![YourControl] = varDate
End Sub
24.) Debug / Compile Save/Close the code window.
25.) You're ready for the "test drive". If it works... enjoy!
If it doesn't, reply to NG with your specific code and any error messages.
PS....
Nobody will likely believe me when I say that I got about as far as step 16
of this the first time, and suffered a power outage!!!!
Note the addition to my signature... :)
--
HTH,
Don
=============================
Use
My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)
I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.
Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop
================================
"Perry Cheng" <pe******@yahoo.com> wrote in message
news:40*********************@news.frii.net...
Don, thank for your expert advice... however, I am so green that I have
no idea where is the main module. I have never deal with module... can
you go step by step how to place this code... and yes... I don't have
the IsLoad... I can probably find northwind somewhere... but, I really
don't know what I am doing here... sorry. I use tables, query, forms,
reports and that is it. I thought there is a way to add a code in the
actual form itself to get those info from the popup calender... well...
please help.
Sincerely,
Perry
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!