Conditional setfocus

Ask a Question related to Microsoft Access, Design and Development.

  1. #1

    Default Re: Conditional setfocus

    "Mike Mueller" <mikemueller@ecinet.net> wrote:
    >I have a simple form for entering monthly pressure tests.
    >There are only 2 fields of concern to data entry for any
    >given month, cylinder number and monthly pressure. The form
    >has fields on it for all months of 2003 and 2004. I want
    >the form to go to the current month's field automatically.
    >I currently change the code monthly for the setfocus. The
    >remaining months are not tab stops so as soon as the current
    >field is done, TAB takes you to the next record.
    >
    >Control Field= cylinder
    >monthly fields- named on a month_year format, eg June_2003,
    >July_2003 etc
    Mike,

    do you actually have table fields for each month for 2 years in one
    record? If so, you should ASAP change your data structure. You should
    have a field for the year (containing 2003, 2004 etc., may be set per
    default) and one for the month, containing preferably 1, 2, ...12.
    This way you can add records even in 2005 and later without having to
    add new fields (besides, the number of fields in a table si limited).
    Not to mention if there is a change some time requiring more data per
    month.

    Leaving the table structure as it is will cause big problems when
    you'll need sorted lists, groupings etc.

    As for putting together the field names dynamically, here is some
    code:

    Dim strFldName As String

    'Assign the current month' full name to the variable
    strFldName = Format(Month(Date), "mmmm")

    'Concatenate the current year
    strFldName = strFldName & "_" & Year(Date)

    Best regards
    Emilia

    Emilia Maxim
    PC-SoftwareService, Stuttgart
    [url]http://www.maxim-software-service.de[/url]
    Emilia Maxim Guest

  2. Similar Questions and Discussions

    1. SetFocus Problem
      Hi Guys, I have a Problem. I have TextInput Object which has to be selected by default so that the user just start typeing anything in it when he...
    2. SetFocus
      I would like to set the focus automatically to one of the textbox controls on my page, but so far on every page I load I have to set the cursor to...
    3. setFocus within Grid
      How can I have the first row of the datagrid highlighted when the page loads? I have rows highlighting on mouseover, and doubleclick event, but i...
    4. setFocus();
      Hi! I have one start file(swf) where i select language from, and when i have selected a language i go to another swf file...
    5. textbox.setfocus
      Hello! Is it possible on a form to set the focus on a field without having the hole filed selected? cause if I use textbox.setfocus, the hole...
  3. #2

    Default Re: Conditional setfocus

    : "Mike Mueller" <mikemueller@ecinet.net> wrote:
    :
    :: I have a simple form for entering monthly pressure tests.
    :: There are only 2 fields of concern to data entry for any
    :: given month, cylinder number and monthly pressure. The
    :: form
    :: has fields on it for all months of 2003 and 2004. I want
    :: the form to go to the current month's field
    :: automatically.
    :: I currently change the code monthly for the setfocus.
    :: The remaining months are not tab stops so as soon as the
    :: current
    :: field is done, TAB takes you to the next record.
    ::
    :: Control Field= cylinder
    :: monthly fields- named on a month_year format, eg
    :: June_2003, July_2003 etc
    :
    : Mike,
    :
    : do you actually have table fields for each month for 2
    : years in one record? If so, you should ASAP change your
    : data structure. You should have a field for the year
    : (containing 2003, 2004 etc., may be set per default) and
    : one for the month, containing preferably 1, 2, ...12.
    : This way you can add records even in 2005 and later
    : without having to add new fields (besides, the number of
    : fields in a table si limited). Not to mention if there is
    : a change some time requiring more data per month.
    :
    : Leaving the table structure as it is will cause big
    : problems when you'll need sorted lists, groupings etc.
    :
    : As for putting together the field names dynamically, here
    : is some code:
    :
    : Dim strFldName As String
    :
    : 'Assign the current month' full name to the variable
    : strFldName = Format(Month(Date), "mmmm")
    :
    : 'Concatenate the current year
    : strFldName = strFldName & "_" & Year(Date)
    :
    : Best regards
    : Emilia
    :
    : Emilia Maxim
    : PC-SoftwareService, Stuttgart
    : [url]http://www.maxim-software-service.de[/url]

    Thank You for the code. You kind of lost me on the first
    part. I am reading it to say that I should only have 1
    field per year and then 1 field per month. I don't
    understand how I would be able to access the reading from
    any particular month.


    Mike Mueller Guest

  4. #3

    Default Re: Re: Conditional setfocus

    "Mike Mueller" <mikemueller@ecinet.net> wrote:

    >Thank You for the code. You kind of lost me on the first
    >part. I am reading it to say that I should only have 1
    >field per year and then 1 field per month. I don't
    >understand how I would be able to access the reading from
    >any particular month.
    Mike,

    it's worse: 1 field per year and month! :-)

    With the info you gave until now, here is an example how the data
    would be stored in the table:

    MyYear MyMonth CylinderNo Pressure
    ---------------------------------------------
    2003 1 01 123.45
    2003 1 02 456.78
    2003 2 01 345.345
    2003 2 02 111.11
    2004 1 01 222.22
    2004 1 02 333.33

    etc.

    Now for ex if you would want to see the data for a given year, you can
    use such a query:
    SELECT * FROM MyTable WHERE MyYear = 2003

    If you want to see the data for a given year and a given month, then:

    SELECT * FROM MyTable WHERE MyYear = 2003 AND MyMonth = 12

    If you would want to average the data for a given year and a given
    cylinder, then (untested, so beware of correct syntax!):

    SELECT Avg(Pressure) FROM MyTable GROUP BY MyYear WHERE Cylinder=01
    AND MyYear = 2003

    If you would want to see the data for a given month over the years,
    then:

    SELECT * FROM MyTable WHERE MyMonth = 4

    In all these examples you can use a form control or a function instead
    of explicit 2003 or month 12 or cylinder 01.

    To enter the data you could use a continuous form where the user
    enters a new record for each cylinder per month. You could fill the
    current year by setting the DefaultValue property of the control to:
    =Year(Date), same for the month:
    =Month(Date) (this returns the current month).

    And if you would want to display the real names for the months, you
    could use a combo with a 2 columns value list: number and name, like
    this:

    1;January
    2;February
    3;March

    etc., sorted as you like, first column bounded and hidden. You would
    store the number in the table and the user sees the friendly name.
    This would help you when you need sorting the months chronologically.

    And the name of all this theory is: a database is not a spreadsheet
    :-) Please don't feel offended, but this is the core of it, really.

    Best regards
    Emilia

    Emilia Maxim
    PC-SoftwareService, Stuttgart
    [url]http://www.maxim-software-service.de[/url]
    Emilia Maxim Guest

  5. #4

    Default Re: Conditional setfocus

    There are heaps of ways to do this.
    A simple way is to name the month fields
    mnth1
    mnth2
    mnth3
    ....
    mnth12

    the code below will do the job...

    Private Sub Form_Open(Cancel As Integer)
    Me.Controls("mnth" & DatePart("m", Date)).SetFocus
    End Sub

    you can alway play with
    ? format(date(),"mmm") returns "Jul"
    ? format(date(),"mmmm") returns July"
    ....thus controls with the month name as part of the name can be use as well.
    --

    peter walker MVP

    Please post replies to the news group so everyone can benefit.
    [url]www.papwalker.com[/url]

    "Mike Mueller" <mikemueller@ecinet.net> wrote in message
    news:ukMBF5AQDHA.1552@TK2MSFTNGP10.phx.gbl...
    > I have a simple form for entering monthly pressure tests.
    > There are only 2 fields of concern to data entry for any
    > given month, cylinder number and monthly pressure. The form
    > has fields on it for all months of 2003 and 2004. I want
    > the form to go to the current month's field automatically.
    > I currently change the code monthly for the setfocus. The
    > remaining months are not tab stops so as soon as the current
    > field is done, TAB takes you to the next record.
    >
    > Control Field= cylinder
    > monthly fields- named on a month_year format, eg June_2003,
    > July_2003 etc
    >
    > Mike
    >
    >

    peter walker Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139