Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I reuse "date" on different forms

Status
Not open for further replies.

beannie

Technical User
Aug 14, 2002
2
0
0
US
Friends,

How can I reuse the same "date" repeatedly on various different forms created under different tables? (Of course all forms are within the same database.)
Example: "hireDate" needs to appear on every corner of each form. Can someone suggest a macro or VB code for me?

Thanks in advance.
Beannie
 

Create a module and a global variable in it and then assign the date value to it:

Option Explicit
Global dtHireDate as Date

Everytime you are looking to a record that changes the hiredate value, just simply assign the new value in the form or code you are in:

dtHireDate = rsMyTable.Fields("dtEmployeeHireDate")

then on the forms assign that variable to the label or text field:

Form1
Label1.Caption = dtHireDate

Form2
Label2.Caption = dtHireDate

HTH
Alcar
 
I don;t work with Macros, but in VB you simply create a global variable gHDate as variant, and on each form you place a Label control lHDate, and then on the form Activate event you simply add the following line of Code:

lHDate.Caption = Format(gHDate, "MM/DD/YYYY")

From a database record using DAO with a global Variable, DB opened as a global recordset object, your form activate might look like this:

.
.
Dim Sql as String
Dim rs as Recordset

Sql= "SELECT Table.* FROM Table WHERE Table.Field=Some Unique Value"
Set rs=DB.OpenRecordset(Sql, DbOpenDynaset)
if rs.recordcount<1 then
'Trap Error
end if
lHDate.Caption=Format(rs!DateField,&quot;MM/DD/YYYY&quot;)
set rs=nothing
end sub


Hope it helps,

Hunter
 
Make a public function. For example, if you enter = PopulateDate() in the control source of a text box, the following code will will return now(). (OK, not very practical, but it gives you the idea)

Public Function PopulateDate()
PopulateDate = Now()
End Function

You'll probably want to return a recordset based on a value in your form... Tyrone Lumley
augerinn@gte.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top