Forms using input mask help

Me.FileName must not be the name of that control. Looking back over your posts I think I guessed wrong, it's probably CntrlFileName.
 
Does the order of the Events (as seen on the Code page) make any difference?

None at all, as far as I'm aware. The only one that MIGHT matter is if you have a custom function you call before it's defined, but I'm pretty sure VBA isn't that picky like some more formal computer languages.
 
Its getting late in the day, and I'm sure your tired of this. So I copied my db, eliminated names, and zipped it (attached). If you would be so kind, what I would like to have in the end is to be able to open the Form, and have the FileName field be ready to accept new data. This includes having the mask displayed and the cursor in the correct position:

2013-"cursor"_-__-____

when the "New Record" button is clicked, I would like the form to return to this position, ready to accept a new record.

FYI I am learning a tremendous amount by doing this. I apologize for the persistence. It seems that this is "learning" in the digital age. I cannot thank you enough!
 

Attachments

I will try to look at it Monday, but if you get to it before me, just change that Me.Filename to Me.CntrlFileName and I think it will work, unless I've misunderstood your control name entirely.

I'm super curious about the double-keypress thing, though.
 
Where do I try:

Me.CntrlFileName

?

I tried:

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

Still getting the "Compile Error"
 
It is the control on your form that you have named [File Name].

So
Code:
Private Sub Form_Current()
If Me.NewRecord Then Me.File_Name.SetFocus
End Sub
 
Okay, so I got a chance to look at your uploaded database. It definitely did the double-keypress thing, but I got it to stop by wiping out the Input Mask, closing and saving the form, then opening it up again and reentering the Input mask. I still have no idea why it was doing that. For reference your input mask is "2013-"00\-00\-000000;0;_

Also there were related errors in your code for referencing [File_Name] in your Click and GotFocus events. Once I got it working, I saw that 5 was the correct value, not 6, so I changed that too.

Compare the below to what you have in your live database:
Code:
Option Compare Database
Option Explicit

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_Current()
    If Me.NewRecord Then Me.File_Name.SetFocus
End Sub

Private Sub Form_Load()
    DoCmd.GoToRecord acDataForm, "DidsonObservationData", acNewRec
End Sub
 
Thanks David! The form now behaves the way I want other than the double click entry problem. I deleted the mask, saved the form, and re entered the mask as per your instructions, and it did not change this behavior. I will continued to play with this.

For my sake, I have to questions. There were 2 differences between the code I had and the code you gave me:

1) I did not have the "Option Explicit" in the beginning. What is this?

2) The name of the field is "FileName" not "File(_)Name" There is no space. Why does "File_Name" seem to work?
 
0) Really bizarre. I also added and removed the input mask from your table, but that shouldn't have had any effect. You might try it anyway... save and backup first!

1) Option Explicit is good coding practice - it means the VBA editor will warn you more often BEFORE you run code that is likely to error out (it forces you to Dim your variables, among other things) http://www.vbforums.com/showthread....at-is-Option-Explicit-and-why-should-I-use-it

2) You and I were both getting confused by this. Your FIELD in the TABLE is called [FileName]. Your CONTROL on the FORM is called [File Name]. Since you can't have spaces in the VBA Sub call, underscore works as a substitute. You can also use [File Name] in some places, but spaces are problems in general. If you want to rename it something without spaces, you might consider CntrlFileName
 
Thanks Again David,
You've been a ton of help. I will keep looking into the entry issue. The rest of my issues have been solved. I'll let you go for now.
 
Glad I could help with most of it. The other thing you might try is to delete the CONTROL (not the table field), compact and repair your database, then re-add it and your input mask again. Something seems to be goofy in there but starting the control from scratch will probably restore it to good working order. Just remember to save your VBA somewhere for when you have to re-enter it (only the ones for that control will disappear).
 

Users who are viewing this thread

Back
Top Bottom