Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2002
    Posts
    23

    Unanswered: Insert Current Month in a Combo Box

    Hello-

    What I'm trying to do is insert the current month into a combo box on a form. Right now, I'm using a table with all 12 months in it, running a query on that table, and displaying the results of that query in the combo box on the form. I have a form function called CurrentMonth that looks like this:

    Function CurrentMonth()
    CurrentMonth = DateSerial(Year(Now), Month(Now), Day(Now))
    End Function

    Because I only want the current month, not a short, medium, or long date, I have put the format "mmmm" inside the "Format" property of the combo box. This does display the current month initially, but when I select another month from the drop-down combo box, I get the following error:
    "The value you entered isn't valid for this field."

    I have tried different settings on the table to try to get the format the way I want it, but haven't found anything that's been working. If anyone has any ideas, I would greatly appreciate it. Thanks much!

    I created a tiny DB to recreate what has been happening, so if you need it, I can email it to you. It's only a 126KB file. Let me know! Thanks!

    littlemadfox

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    your function CurrentMonth doesn't return a month.

    post your db - it always makes life simpler.

    izy

  3. #3
    Join Date
    Jul 2002
    Posts
    23
    How can i post my db? It wouldn't let me attach a *.mdb file.

    Let me know! Thanks.

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    zip it.
    (www.winzip.com for a free try-before-you-buy)

    or just rename it
    myfile.mdb -> myfile.jpg
    ...but don't forget to say you've renamed it or folk will get confused.


    izy

  5. #5
    Join Date
    Jul 2002
    Posts
    23
    Here's the sample DB for what I am trying to do. I zipped it and attached it. Please give me any help that you can. Thanks much!

    littlemadfox
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sorry lmf,

    "The current user doesn't have permission to convert or enable the database".

    ...and it's bedtime. i'm out tomorrow, but i'll check in again in 48 hrs if you don't get an answer before then.

    izy

  7. #7
    Join Date
    Jul 2002
    Posts
    23
    Thanks for trying. I think that error is because this is an Access 97 database. I forgot to specify that. Anyone that has Access 97 installed and knowledge on the subject, please help!

    littlemadfox

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ...and some fell on stony ground.



    i can't open your db (me = a2k), so maybe you can describe your problem in more detail.

    ? what fields do you have in your tables
    ? what data is supposed to be in the combo
    ? what is supposed to happen when the user selects something in the combo


    izy

  9. #9
    Join Date
    Jul 2002
    Posts
    23
    Well, to simplify this problem, I'll explain what's in the database that I posted:

    Table: MONTH
    Two fields:
    monthNumber (1-12) -- number
    monthName (January-December) -- text

    Query: Month Query
    SELECT monthName
    FROM MONTH
    ORDER BY monthNumber;
    This query simply returns the months in the order they are in a year.

    Form: Display Month
    Field: monthCombo
    In this form, I set the RowSource to use the MonthQuery so that the combo box will hold all of the months in the order that they occur throughout the year.

    I also have a small funtion that is as follows:
    Function CurrentMonth()
    CurrentMonth = DateSerial(Year(Now), Month(Now), Day(Now))
    End Function
    The function is set as =CurrentMonth() in the DefaultValue property.

    My desire is to have the current month pop up when the form is opened. For example, if it is June 1, 2003, June would show up. Pretty self-explanatory. However, the date can only be formatted as a short, medium, or long date and those include various parts of the date, which I don't want all of those parts. I just want the Month. There is a Format property of a combo box that says to put "mmmm" in the Format field to only show the month. I tried that and got the error message as shown on the attachment. My vb isn't the most proficient, but I do what I can to get by. I found that function on the web somewhere, so I tried it and it didn't work the way I wanted it to.

    Any help you could provide me with would be greatly appreciated! Please let me know if you need any more information. Thank you so much for trying to help me out. I really appreciate it.

    littlemadfox
    Attached Thumbnails Attached Thumbnails month error message.jpg  

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    real-life slows you down: sorry for the delay.



    i insist that your function CurrentMonth does NOT return a month!

    try CurrentMonth = month(now())
    ...at least it will return a month as an integer.

    now try CurrentMonth = monthname(month(now()))



    how are we doing?


    izy

  11. #11
    Join Date
    Jul 2002
    Posts
    23
    Thanks for your reply, but I already got something to work. This is what I did:

    monthCombo.Value = Format(DateSerial(Year(Date), Month(Date), 1), "mmmm")

    It did just what I wanted to do, but thank you for trying to assist me. Thanks much!

    littlemadfox

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •