Forms using input mask help

FRO

Registered User.
Local time
Today, 08:23
Joined
Dec 13, 2013
Messages
15
Hello Access Forum,
I am trying to force a form to display the "literal" portion of my input mask, and place the cursor after this portion. I have attached two screenshots to help demonstrate what I am looking for.

When I click "New Record", a new record is created with the "File Name" box being the first TabOrder. However, neither my input mask or my cursor appears in the box ("formbefore" pic). The input mask does appear after I click in the box, and the cursor appears wherever I click.

What I want is for the input mask to be displayed, and the cursor to be positioned in the first position of the fillable part of my input mask when the new record loads ("formafter" pic), so I can immediately begin inputting data without having to click in the first box. Any help would be appreciated.

Thanks!
 

Attachments

  • formbefore.jpg
    formbefore.jpg
    30.5 KB · Views: 97
  • formafter.jpg
    formafter.jpg
    33.7 KB · Views: 92
SetStart is going to be your friend here.... I can't tell if it'll be 4 or 5, kinda depends on whether you're storing the dash or not. Play with it in the Click event, but be aware you'll have to duplicate the code in the GotFocus event (I don't know why, Access is cranky that way).

Also I suspect it is not showing your '2013-' part until you create a record, does that seem accurate? Please tell me that "2013" is a default value, not part of the mask... what happens in January??
 
Thanks for the help. Working backwards, yes the "2013-" part is in the mask. I just change it to "2014-" when that occurs. How would that be any different than setting the default value to "2013-", then having to change that?

I am not a programmer, and do not know the syntax rules perfectly. Where and how do I use SetStart? I was avoiding putting anything in the OnClick event because I do not want to have to click in the box. Can the cursor be in the box and ready when the new record page loads?

Thanks again!
 
Setting it as the default value (or auto-inserting it when you create a new record) STORES the 2013 in your record. Having it as part of the mask will make all your 2013 records LOOK like 2014 records as of January 1, which isn't what you want I'm sure... (don't worry, we can go back and fix the old ones with an UPDATE query if needed).

Try this... you may need to tweak the code a bit for your field names, etc.
Code:
Private Sub CntrlFileName_GotFocus()
    If Me.NewRecord Then Me.CntrlFileName = Year(Date()) 'set to 2013 today, 2014 on Jan 1
        
    Me.ActiveControl.SelStart = 5 'maybe, fiddle with it to get it right
End Sub
Once you get it working perfectly, just copy it into the Click event. GotFocus will trigger when the control is entered for any reason, including when the form is loaded (you can play with Tab Order to make sure that control gets the cursor first).
 
I completely see your point with regards to the "2013-" mask. However, I believe there is a missing piece here. The "File Name" field, receiving the input mask, is not an actual date. It is a text, and formatted as such. This "file name" is generated from a piece a equipment we are using. Its like naming your dog "13". No math will have to be done to it, so keeping it a text is fine with me.

I will try the SetStart code you provided to try to get the cursor in the right spot.

A big help!
 
David,
I used your SetStart code in the Got Focus and OnClick events. As a result, when I open the form for the first time, it does exactly what I want. However, after I enter data and click the "New Record" box, a new record page opens without any mask or cursor. Again, if I click in the File Name box, the mask shows up and the cursor is wherever I clicked. And FYI the File Name box is first in the Tab Order. Could this be something wrong with the "New Record" box event? The New Record event is an On Click macro that I stole from the web.

Not to pile on, but on another topic, after I insert the cursor for the first time in a record, I have to type the first key twice. The first time makes the little "pencil" appear (I believe indicating data entry), the second time enters the number. This there a way to stop this two-step process?

Many Thanks!
 
I completely see your point with regards to the "2013-" mask. However, I believe there is a missing piece here. The "File Name" field, receiving the input mask, is not an actual date. It is a text, and formatted as such. This "file name" is generated from a piece a equipment we are using. Its like naming your dog "13". No math will have to be done to it, so keeping it a text is fine with me.
Right, but what I'm saying is that (as I understand your process, anyway) all of your "2013-XXX..." records are going to look like "2014-XXX..." once the new year starts! You can actually check this now by changing your mask temporarily. I think there is an option in Access to store the mask as part of the field, in which case you might be safe. But I can't be sure and that's why I'm worried.
 
David,
I used your SetStart code in the Got Focus and OnClick events. As a result, when I open the form for the first time, it does exactly what I want. However, after I enter data and click the "New Record" box, a new record page opens without any mask or cursor. Again, if I click in the File Name box, the mask shows up and the cursor is wherever I clicked. And FYI the File Name box is first in the Tab Order. Could this be something wrong with the "New Record" box event? The New Record event is an On Click macro that I stole from the web.
What does your NewRecord macro do?

You can move the part where it autoinputs the 2013- for you to the New Record macro/code, but I'm more curious about why your cursor isn't show up there. Did you verify that Tab Order is set correctly to start in that field? You can force it to jump to that field by code if needed...
 
Not to pile on, but on another topic, after I insert the cursor for the first time in a record, I have to type the first key twice. The first time makes the little "pencil" appear (I believe indicating data entry), the second time enters the number. This there a way to stop this two-step process?
That's very odd. Did it do that before we fiddled SetStart? My only guess without actually seeing the database is that your cursor might be 'on' the dash and thus the first character is being lost... but it really shouldn't work that way.

If your data is not sensitive, you can zip a copy and post it here.
 
Unfortunately, the db has peoples names that I shouldn't post. Here is the code for the FileName box:

Private Sub File_Name_Click()
Me.ActiveControl.SelStart = 5
End Sub

Private Sub File_Name_GotFocus()
Me.ActiveControl.SelStart = 5
End Sub

Private Sub Form_Load()
DoCmd.GoToRecord acDataForm, "DidsonObservationData", acNewRec
End Sub

Private Sub Form_Open(Cancel As Integer)

End Sub

This results in the correct behavior only when the form is first opened, or after I click in the FileName box. I would like this to happen when the new record page loads (not requiring a click). I have checked that the TabOrder begins with FileName.

A screenshot of the "New Record" macro is attached. It is in the On Click event. I don't know if this will be helpful. This is getting above my head.

As for the "odd" part. I have attached before and after screenshots of what happens AFTER I click into the FileName box. The "Formbeforefirstentry" is what the form looks like before I type any key (to enter data). Note the black sideways triangle on the left side. When I type the first key, the form changes to the "Formafterfirstentry". Note the pencil on the left side. Only after this does typing result in data entry. For example, if I want the first space in my input mask (after the "2013-" to have a "1" in it, I need to type "1" twice.
 

Attachments

  • newrecordmacro.jpg
    newrecordmacro.jpg
    29.8 KB · Views: 82
  • Formbeforefirstentry.jpg
    Formbeforefirstentry.jpg
    36.2 KB · Views: 95
  • Formafterfirstentry.jpg
    Formafterfirstentry.jpg
    36.8 KB · Views: 90
The little pencil tells you that the record has been edited, but not yet saved. So pressing that first key is doing...something, even if you're not seeing it. Very odd.

Try this. Go to a new record, go to FieldName, press that one key to get the pencil. Then without doing anything else in that field (unless your input mask requires it, in which case you might remove it temporarily), Close the form. You might have to enter some other Required fields...

Anyway, then go open up the table/query behind this form, and screenshot or tell me exactly what it says in File_Name field for that new record.
 
Also, in your form's Current event procedure, put this:
Code:
If Me.NewRecord Then Me.FileName.SetFocus
 
For the first question, I cannot perform this test because the FileName is also my Primary Key, and I cannot close the form without completing it. It "Cannot contain a null value". Even if I delete the mask, something has to be entered.

For the second question, where is the Current event? I do not see that as an option in my Events property sheet. Would I code it as:

"Private Sub File_Name_Current()"?
 
Second question first: On the Property Sheet, Event tab, first entry will be Current. Click the [...] at the end of the row and it will build the frame for Form_Current for you (you want to let Access do this for you normally, because some events have variables they pass to the code, and some don't). You won't see Current unless you're in the 'Form' level of Design View (click the little box in the top left corner).

First question second: Okay, try going to the Immediate Window at the bottom of your VBA screen, and type
Code:
? Dmax("File_Name","tablename")
(replacing tablename with the name of the TABLE that is behind this form)

Tell me exactly what it outputs, then do the same for DMin.
 
The "FileName" box does not have a Current property option. See Attached. The first option is On Click.

Running DMax returns the most recent entry into the FileName field
"2013-07-09-140000"
Running the DMin returns the first entry:
"2011-05-15-080000"
 

Attachments

  • NoCurrent.jpg
    NoCurrent.jpg
    93.2 KB · Views: 70
Confirmed that I don't have a Current property. I manually added:

Private Sub Form_Current()
If Me.NewRecord Then Me.FileName.SetFocus
End Sub

It would not run and prompted that Form_Current() does not exist.
 
A field does not have a Current event, a FORM does.

Current_Event.gif


See that black box in the top left? Click that on your form, then go to the Event tab and click Current (but you want Code Builder, not Macro). You may need to wipe out your hand-typed version... though I admire your persistence in hand typing that stuff!
 
The "FileName" box does not have a Current property option. See Attached. The first option is On Click.

Running DMax returns the most recent entry into the FileName field
"2013-07-09-140000"
Running the DMin returns the first entry:
"2011-05-15-080000"
Okay good, then my fears about your mask are unfounded (I think). You must have inadvertently set it to store the mask as part of the data, which is basically the equivalent of what I was telling you to do. Good enough, we have bigger fish to fry.

Once you get your Current event working, let's try changing SetStart to 6 and see if that fixes this double-key problem.
 
I've figured out the Form_Current thing ("the black box in the upper left..." took me awhile). However, when I enter:

Private Sub Form_Current()
If Me.NewRecord Then Me.FileName.SetFocus
End Sub

after I save it, I try to close the Code View, I get the following error:

"Compile error:
Method or data member not found."

When I click OK, the Private Sub Form_Current() is highlighted yellow and the .SetFocus is highlighted blue.
 
Does the order of the Events (as seen on the Code page) make any difference?
 

Users who are viewing this thread

Back
Top Bottom