Get a module to fill in a text field

G

Guest

I have a module that converts the date into the gregorian (juilan date) date.
I am tring to use the moduel to automatically fill in the field using the
current date and this function moduel. The problem I am having is tying the
module to the text field in Access. I inputed the module below to see if any
of you see any problem with it.

Function CDate2Julian (MyDate As Date) As String

CDate2Juilan = Format (Mydate - DateSerial (Year(MyDate) - 1,12,31), "000"

End Function
 
G

Guest

Hi.
I am tring to use the moduel to automatically fill in the field using the
current date and this function moduel.

As an example, the following line of code in the form's module would assign
today's date to a text box named txtJulianDate:

Me!txtJulianDate.Value = CDate2Julian(Date)
The problem I am having is tying the
module to the text field in Access.

It can be assigned during some event of the form or control. For example,
one may assign the value passed back by this function by using code such as
the following:

Private Sub JulianDateBtn_Click()

On Error GoTo ErrHandler

Me!txtJulianDate.Value = CDate2Julian(Me!txtSomeDate.Value)

Exit Sub

ErrHandler:

MsgBox "Error in JulianDateBtn_Click( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

.. . . where txtJulianDate is the name of the text box that the Julian Date
will be displayed, and txtSomeDate is the name of the text box that has a
Gregorian Date that needs the conversion. This value can be assigned with
the click of a button (named JulianDateBtn in the example above), or in some
other event of the form (such as the OnFormOpen( ) event), or in some control
event (such as the OnAfterUpdate( ) event of the text box with the Gregorian
Date).

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
D

David C. Holley

In the Immediate Window have you typed

?CDate2Julian ([some valid date])

That will confirm wether or not the function is returning a value.
From there its a matter of writting additional code to actually plop
the value from the function in a text box. You'll need to figure out at
what *EVENT* do you want the text box populated. For example, it might
be that you want the text box populated when entering a new record. For
that, you would set the .DefaultValue for the text box to
..DefaultValue(Now())

Or it might be that you want the text box populated after you enter
value in another field. In that case you would use the AfterUpdate()
event of the field as in...

Private Sub enterDate_AfterUpdate()

Me.[controlName] = CDate2Julian (Me.enterDate)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top