Solved

Spell Check in Access 2013 subform

Posted on 2014-09-12
12
411 Views
Last Modified: 2014-09-12
I'm using the code below to spell a field in a subform, it fails at .SelStart = 0, it does pull the characters from the text field for checking. It works in the main form.

If Len(Me!Text14 & "") > 0 Then
        With Me!Text14
            .SetFocus
            .SelStart = 0
            .SelLength = Len(Me!Text14)
        End With
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdSpelling
        DoCmd.SetWarnings True
    End If
0
Comment
Question by:dgravitt
  • 8
  • 4
12 Comments
 
LVL 84
ID: 40319140
Are you certain Text14 is the name of the Textbox (more on that later)? If so, you might try this:

If Len(Me.Text14 & "") > 0 Then
        With Me.Text14
            .SetFocus
            .SelStart = 0
            .SelLength = Len(Me.Text14)
        End With
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdSpelling
        DoCmd.SetWarnings True
    End If

Open in new window

Basically, I've changed the ! to a . instead. Better yet, change the name of that Textbox to something meaningful, like "txCustomerName", and you will be sure that you're referring to the correct value.

Also, regarding Subforms - is this code running in the Mainform, or in the Subform? If it's running in the Mainform, and if you're trying to execute it against objects in the Subform, you'll have to change the textbox reference.

Regarding nameing: You really, really, really should adopt a Nameing Convention for your programming. There are several concepts out there, but essentially you should give meaningful names to all objects, and you should preface those names with a 1 to 3 character tag that indicates the "type" of object they are. For example, "txCustomerName" indicates the control holds the Customer's Name, and that it's most likely a textbox. "cboCustomerType" would indicate the control holds the Type of Customer, and is most likely a Combobox. Doesn't really matter what sort of nomenclature you use, so long as you're consistent, and it makes sense to you.
0
 

Author Comment

by:dgravitt
ID: 40319162
I changed the ! to a .  Still fails at the same point. I included a stop in the code so I could verify the the value being checked is correct. I am checking in the subform. The way I have this setup is, I have an "entry" section in the header. When all fields are filled in, the user clicks add, and then it show in the list in the Detail section. I'm Spell Checking a field in the header on exit from the field.
0
 
LVL 84
ID: 40319331
So is the code you're showing running in an event on the MAIN form, or on the SUBform?

If it's on the MAIN form, then you'll have to refer to the controls on the SUBform differently. For example, if Text14 is on the SUBForm, and you're running the code on the MAIN form:

If Len(Me.YourSubformCONTROL.Form!Text14 & "") > 0 Then
        With Me.YourSubformCONTROL.Form!Text14
            .SetFocus
            .SelStart = 0
            .SelLength = Len(Me.YourSubformCONTROL.Form.Text14)
        End With
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdSpelling
        DoCmd.SetWarnings True
    End If

Open in new window

Note that YourSubformCONTROL is the Subform Control on the main form, and may or may not be named the same as the Form you're using as a Subform. To get the name of the control, click ONCE in the subform, then look at the Properties of the object. It should say "Subform/Subreport" in the Properties sheet.

Subform
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:dgravitt
ID: 40319367
Yes, it is running in the subform. I tried the above and get an error on finding the field. Does it matter that this is an unbound field? As stated previously, when I run it the way it was with a Stop in the code, I can verify that it has captured the data in the text box, it just doesn't process it.
0
 

Author Comment

by:dgravitt
ID: 40319377
this is a shot of my form(s). I'm trying to check the desription field at top of the subform.
screen.jpg
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40319479
Does it matter that this is an unbound field?
It might.

When you use SelStart and SelLength, does the text in that control get the Focus, and is it highlighted?
0
 

Author Comment

by:dgravitt
ID: 40319489
That is where the error happens is on SelStart. Sorry, but I must ask about your Icon, is that South Carolina?
0
 

Author Comment

by:dgravitt
ID: 40319511
OK, it is the unbound field. When I move it down to the Detail part and set it on the description field it works. How can I make it check on the add record? I tried it on After Update, but that doesn't work in insert.
0
 

Author Comment

by:dgravitt
ID: 40319521
Got it. I added the check spelling to event procedure after running the insert. I'm going to give you credit because your answers where very thought provoking.
0
 

Author Closing Comment

by:dgravitt
ID: 40319523
Thanks for working through this.
0
 
LVL 84
ID: 40320266
Thanks - and yes, my avatar is the traditional Block C logo for the mighty South Carolina Gamecocks!!!
0
 

Author Comment

by:dgravitt
ID: 40320344
I will be a huge Gamecock fan this weekend. I'm GA Tech. Thanks again for your help.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question