show current moth

illusion

Registered User.
Local time
Today, 12:51
Joined
Mar 25, 2004
Messages
16
hello,

i have a list menu ("September";"Octomber";"November";"December";"January";"February";"March";"April";"May";"June";"July";"August").

is there something that i can put in the default value of this field to display current month ?

thanks
 
two ways

MonthName(DatePart("m",Date()))

MonthName(Month(Date()))

either will do just fine. I typically use the latter because it's less code.
 
it doesn't work. it returns on my list #error....

i want to show e.g March as the first choice is that the needed code ?
 
I'm sorry, I didn't read your question carefully enough. No, that won't work for that..

hang on and I'll whip something up.
 
OH sorry its ok... it inserts the month but the caption on the new record row writes "error" but when u insert a new record it puts the current month automatically.
Thanks.
 
sorry it took so long.. baby needed to eat ;)

Use the following code on your desired event. Probably your form open event or current event.

PHP:
Dim FirstSource As String, TotalSource As String, NewSource As String
Me.theMonth.RowSourceType = "value list"

FirstSource = MonthName(Month(Date)) & ";"
TotalSource = "September;Octomber;November;December;January;February;March;April;May;June;July;August"

NewSource = FirstSource & Replace(TotalSource, FirstSource, "")
Me.theMonth.RowSource = NewSource
Me.theMonth.Selected(0) = True

this will show the current month as the first choice and have it selected.

[edit] the board is putting a space in the word February, but there shouldn't be one.
 
Last edited:
This is posted in the "Tables" Forum, are you using/wating a lookup value in a table or a form?

Table (i don't recomend this):

Code:
Default Value: Format(Date(), "mmmm")

Form (used for entering data, i like :D ):

Code:
Private Sub Form_Load()
Dim dtNewMonth As Date

Me.cboMonth.RowSourceType = "Value List"

    Do Until Me.cboMonth.ListCount = 12
        dtNewMonth = DateAdd("M", 1, dtNewMonth)
        Me.cboMonth.AddItem Format(dtNewMonth, "mmmm")
    Loop
  
Me.cboMonth = Format(Date, "mmmm")

End Sub
The vb code is fully automated, you dont even have to set up anything. :eek: :D
________
BUY EASY VAPE VAPORIZER
 
Last edited:
but that won't put the current month at the top of the list..
 
illusion said:
is there something that i can put in the default value of this field to display current month ?

ell, forget everything that's been said on this thread. All you need to put in the Default Value is Format(Date(), "mmmm")

I'd suggest, however, if you are storing this value in a table that you change you combobox's Value List to this:

1;"January";2;"February";3;"March";4;"April";5;"May";6;"June";7;"July";8;"August";9;"September";10;"October";11;"November";12;"December"

For this to work, you'd also need to change the Column Count to 2, the Column Width to 0, the Default Value to Month(Date()), and, in the table design, the field's data type to Number.

I suggest this because the amount of space taken up by a number is a lot less than that taken up by text. It's minimal, but it's still space saved. It's also faster when doing searches, counts, etc. on numeric data than textual data.
 
a.sinatra said:
#1. Dude, shut up, you havent even tried it.
#2. It does put it at the top; click the drop down and march is the first month selected, if you want you would have to scroll up to select jan & feb
#3. My way keeps the months in a ogranized fashion there is no reason why the months shouldnt be unorganized (ex: march, jan, feb, april)
#4. I just tried your code and get a compile error...


Well that was rude.. what is your general problem? All I've seen from you on this forum is nothing but attitude.. shove it up your ass.
 
Last edited by a moderator:

Users who are viewing this thread

Back
Top Bottom