Turn off Name AutoCorrect with VBA?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BradHodge
    Recognized Expert New Member
    • Apr 2007
    • 166

    Turn off Name AutoCorrect with VBA?

    I am being stricken with the A2K Name AutoCorrect bug with regards to reports changing margins and orientation. I understand that you can turn this feature off when creating objects, but I am guessing (incorrectly I hope) that this will fix this problem only for my computer.

    If this is indeed the case, does anyone know if it's possible to turn autocorrect off as soon as a user opens the database (via a vba module or something)?

    Thanks!

    Brad.
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    The following article explains how you can manually turn it off, if you need to use VBA let us know I am sure I can something to fit your needs.

    "Taking the mystery out of Name AutoCorrect in Access."

    Comment

    • BradHodge
      Recognized Expert New Member
      • Apr 2007
      • 166

      #3
      Originally posted by Denburt
      The following article explains how you can manually turn it off, if you need to use VBA let us know I am sure I can something to fit your needs.

      "Taking the mystery out of Name AutoCorrect in Access."

      http://office.microsoft.com/en-us/ac...345661033.aspx
      _______________ _______________ _______________ _______________ ______
      Looks like that link you sent is no longer active (or just a problem with the site).

      I have had no problem manually turning off Name AutoCorrect. I just need to know if you manually turn it off before creating Access objects, will this translate to other users PCs using the network version of the database?

      If not... I do indeed need some advice on how to use VBA to turn off Name AutoCorrect.

      Many thanks!

      Comment

      • Denburt
        Recognized Expert Top Contributor
        • Mar 2007
        • 1356

        #4
        I do believe this is a turned on and off per database type of an item. So if anyone is using that db then it should be set for them as well.

        I do indeed need some advice on how to use VBA to turn off Name AutoCorrect.
        That may take some effort I will try and do what I can if you or anyone else manages to find it please post it as it could be useful to others. Thanks

        Comment

        • BradHodge
          Recognized Expert New Member
          • Apr 2007
          • 166

          #5
          Sweet! That's what I was hoping to hear. I am currently working on the first report I have built from scratch since turning off the AutoCorrect. I'll update you when I try it out.

          Comment

          • BradHodge
            Recognized Expert New Member
            • Apr 2007
            • 166

            #6
            Well... Making progress, but...

            It is now holding the Margins and the landscape orientation of the page, but it loses the "Legal" page size setting (reverts to Letter).

            Thoughts?

            Brad.

            Comment

            • Denburt
              Recognized Expert Top Contributor
              • Mar 2007
              • 1356

              #7
              In my module I typed in papersize highlighted it hit F1...Try that for AutoCorrect :)

              Help file shows the following:
              PaperSize Property
              See AlsoApplies ToExampleSpecif icsReturns or sets an AcPrintPaperSiz e constant indicating the paper size to use when printing. Read/write.

              AcPrintPaperSiz e can be one of these AcPrintPaperSiz e constants.
              acPRPS10x14
              acPRPS11x17
              acPRPSA3
              acPRPSA4
              acPRPSA4Small
              acPRPSA5
              acPRPSB4
              acPRPSB5
              acPRPSCSheet
              acPRPSDSheet
              acPRPSEnv10
              acPRPSEnv11
              acPRPSEnv12
              acPRPSEnv14
              acPRPSEnv9
              acPRPSEnvB4
              acPRPSEnvB5
              acPRPSEnvB6
              acPRPSEnvC3
              acPRPSEnvC4
              acPRPSEnvC5
              acPRPSEnvC6
              acPRPSEnvC65
              acPRPSEnvDL
              acPRPSEnvItaly
              acPRPSEnvMonarc h
              acPRPSEnvPerson al
              acPRPSESheet
              acPRPSExecutive
              acPRPSFanfoldLg lGerman
              acPRPSFanfoldSt dGerman
              acPRPSFanfoldUS
              acPRPSFolio
              acPRPSLedger
              acPRPSLegal
              acPRPSLetter
              acPRPSLetterSma ll
              acPRPSNote
              acPRPSQuarto
              acPRPSStatement
              acPRPSTabloid
              acPRPSUser

              expression.Pape rSize
              expression Required. An expression that returns one of the objects in the Applies To list.

              Example
              The following example sets a variety of printer settings for the form specified in the strFormname argument of the procedure.

              Sub SetPrinter(strF ormname As String)

              DoCmd.OpenForm FormName:=strFo rmname, view:=acDesign, _
              datamode:=acFor mEdit, windowmode:=acH idden

              With Forms(form1).Pr inter

              .TopMargin = 1440
              .BottomMargin = 1440
              .LeftMargin = 1440
              .RightMargin = 1440

              .ColumnSpacing = 360
              .RowSpacing = 360

              .ColorMode = acPRCMColor
              .DataOnly = False
              .DefaultSize = False
              .ItemSizeHeight = 2880
              .ItemSizeWidth = 2880
              .ItemLayout = acPRVerticalCol umnLayout
              .ItemsAcross = 6

              .Copies = 1
              .Orientation = acPRORLandscape
              .Duplex = acPRDPVertical
              .PaperBin = acPRBNAuto
              .PaperSize = acPRPSLetter
              .PrintQuality = acPRPQMedium

              End With

              DoCmd.Close objecttype:=acF orm, objectname:=str Formname, _
              Save:=acSaveYes


              End Sub

              Comment

              • BradHodge
                Recognized Expert New Member
                • Apr 2007
                • 166

                #8
                I finally got it working.

                As stated before, turning off the Name AutoCorrect made the report hold it's margins and Landscape orientation. However, the Paper Size continued to revert to Letter.

                I ended up placing this code in the command button that opened the report...

                DoCmd.OpenRepor t "MyReport", acViewPreview
                MsgBox ("You must choose Paper Size: 'Legal' to view/print properly")
                SendKeys "{RIGHT}"
                SendKeys "{TAB}"
                SendKeys "{TAB}"
                SendKeys "%{DOWN}"
                RunCommand acCmdPageSetUp

                This opened Page SetUp and opened the dropdown box for choosing the paper size.

                Thanks for all of your replies and direction Denburt!

                Brad.

                Comment

                • Denburt
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1356

                  #9
                  I am glad you managed to get it working however, I so hate sendkeys... Yes they can get things done but they can be very problematic to say the least. I did a little digging and found the following article and I am sure you will find this useful.




                  The link provides two methods of setting the default printer to legal as well as other properties and I am sure they will produce much more reliable results.

                  Comment

                  • BradHodge
                    Recognized Expert New Member
                    • Apr 2007
                    • 166

                    #10
                    Indeed this appears that it would be a much better method of accomplishing this task. However, it appears that it will only work on Access 2002, 03 and 07. This database is written in 2k. I have however marked this page for use on my next '03 Db!

                    Thanks again for your help.

                    Brad.

                    Comment

                    • Denburt
                      Recognized Expert Top Contributor
                      • Mar 2007
                      • 1356

                      #11
                      You got me on that one drn everyone wants to complain today... lol Try this one, it is 2k compliant, I am so very stubborn. :)

                      Comment

                      • Denburt
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 1356

                        #12
                        Originally posted by Denburt
                        You got me on that one drn everyone wants to complain today... lol Try this one, it is 2k compliant, I am so very stubborn. :)

                        http://support.microsoft.com/kb/302416/en-us

                        Sorry just realized it needs to open it in design view also... I will keep looking.

                        Comment

                        • BradHodge
                          Recognized Expert New Member
                          • Apr 2007
                          • 166

                          #13
                          You are quite stubborn... but if it ends up solving this one... I'll forgive a little stubborness :)

                          Comment

                          • Denburt
                            Recognized Expert Top Contributor
                            • Mar 2007
                            • 1356

                            #14
                            Stuborn me I am back with more. I found two articles on printing using win32 API's if you think this may work for you let us know and we may be able to help with any conversions.
                            The code I am about to paste needs some work for printing a form etc. Basic printing to a default printer (worked for me) using the string in the code. I didn't try to make any adjustments to try and print a form. The one thing is the user will not see any dialog box, this can be remedied but you would need to design one.
                            The following article in this link refers to an issue with duplex printing however the code could possibly work with a few adjustments.


                            This link is where I found the following code. The article states that this is for VB but it will work for VBA. I also made a few adjustments btw.

                            Code:
                            Option Compare Database
                            Option Explicit
                                  Private Type DOCINFO
                                      pDocName As String
                                      pOutputFile As String
                                      pDatatype As String
                                      pPaperSize As Integer
                                  End Type
                                  Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
                                     hPrinter As Long) As Long
                                  Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
                                     hPrinter As Long) As Long
                                  Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
                                     hPrinter As Long) As Long
                                  Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
                                     "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
                                      ByVal pDefault As Long) As Long
                                  Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
                                     "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
                                     pDocInfo As DOCINFO) As Long
                                  Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
                                     hPrinter As Long) As Long
                                  Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
                                     hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
                                     pcWritten As Long) As Long
                            
                            Public sub RunPrint()
                            Dim lhPrinter As Long
                            Dim lReturn As Long
                            Dim lpcWritten As Long
                            Dim lDoc As Long
                            Dim sWrittenData As String
                            Dim MyDocInfo As DOCINFO
                            lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
                            If lReturn = 0 Then
                                MsgBox "The Printer Name you typed wasn't recognized."
                                Exit Sub
                            End If
                            MyDocInfo.pDocName = "AAAAAA"
                            MyDocInfo.pOutputFile = vbNullString
                            MyDocInfo.pDatatype = vbNullString
                            
                            'Not sure of the integer needed for legal play with it and see 
                            debug.print  MyDocInfo.pPaperSize 
                            [B]MyDocInfo.pPaperSize = 1[/B]
                            
                            lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
                            Call StartPagePrinter(lhPrinter)
                            sWrittenData = "How's that for Magic !!!!" & vbFormFeed
                            lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
                               Len(sWrittenData), lpcWritten)
                            lReturn = EndPagePrinter(lhPrinter)
                            lReturn = EndDocPrinter(lhPrinter)
                            lReturn = ClosePrinter(lhPrinter)
                            End Sub
                            Last edited by Denburt; Apr 19 '07, 03:10 AM. Reason: Clean up

                            Comment

                            • BradHodge
                              Recognized Expert New Member
                              • Apr 2007
                              • 166

                              #15
                              Hate to be dense, but compiler didn't like all the Private Declares after the 'End Type'. I looked specifically at the second link that you included and it said to put this code behind a command button. Is there more to it than that? My VBA experience thus far has not included placing all those Private Type, Private Declares and Public Subs one after the other.

                              Thanks,
                              Brad.

                              Comment

                              Working...