Month command

colmac
StarLounger
Posts: 65
Joined: 01 Apr 2011, 18:43

Month command

Post by colmac »

I'm trying to use

=Month([tran_date])

as the default value in a list box, where [tran_date] has just been entered as the previous field on a new record and is therefore not saved yet.

Doesn't seem to make this work though. Can anyone help please

Thanks

Colin

User avatar
HansV
Administrator
Posts: 78621
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Month command

Post by HansV »

The Default Value of a property is set when you move to a new record. At that moment, tran_date has not been entered yet, so the default value of the list box is null (empty).
You could create an After Update event procedure for tran_date:

Code: Select all

Private Sub tran_date_AfterUpdate()
    If Me.NewRecord And Me.ListBox1.ListIndex = -1 Then
        Me.ListBox1.Value = Month([tran_date])
    End If
Replace ListBox1 with the actual name of your list box. The code only sets the value of the list box if you're on a new record and if nothing has been selected in the list box yet.
Best wishes,
Hans

colmac
StarLounger
Posts: 65
Joined: 01 Apr 2011, 18:43

Re: Month command

Post by colmac »

Thank you.

As ever, excellent speed and help. It works perfectly.

Many thanks, it is appreciated