error on acCmdFormHdrFtr - why??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deekay
    New Member
    • May 2010
    • 21

    #1

    error on acCmdFormHdrFtr - why??

    I have a createForm() procedure that appears to be working and putting in controls in the detail section. I want to put the labels in the header section. As this will be a distributed .mde file I want to use vba to dynamically create the form rather than using a template. I wa using the following in order to turn on the Header (and Footer) section.

    I have (after the declaring the variables)
    Code:
    set frm = CreateForm()
    docmd.runCommand(acCmdFormHdrFtr)
    with frm
    .recordSource = tblName
    '... and so on
    I am getting error 2046 'Unable to run command acFrmHdrFtr at this time' on the doCmd line.

    Other posts I've read about this suggest this should be the way to do this. Can anybody help?
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Have you tried something like this:
    Code:
    Dim myForm As Form
    Set myForm = CreateForm()
      DoCmd.SelectObject acForm, myForm.Name, False
      DoCmd.RunCommand acCmdFormHdrFtr
      DoCmd.RunCommand acCmdFormView
      DoCmd.Maximize
    Set myForm = Nothing

    Comment

    • Deekay
      New Member
      • May 2010
      • 21

      #3
      Yes - because I was calling this code from another form, I out in a 'selectobject' line - but the error message still appears at the same place.

      Thanks for the suggestion - any other thoughts?

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        I tried the code above from a module, not a form. Don't know if that might make a difference.

        Is this error happening in the MDE or the MDB?

        Comment

        • Deekay
          New Member
          • May 2010
          • 21

          #5
          Thank you for your replies.
          It's happening in the MDB and in a module that is called from a command button on a separate form. The command button processes other events successfully before reaching this part of the code. The code also works if I take out the line - i.e. it creates the form and then adds controls and saves the form - except that there is no header or footer of course.

          Comment

          • TheSmileyCoder
            Recognized Expert Moderator Top Contributor
            • Dec 2009
            • 2322

            #6
            Did you try the code i posted? I tested that and it worked for me in Ac2007. Otherwise try to post the rest of your code.

            Comment

            • Deekay
              New Member
              • May 2010
              • 21

              #7
              I'm working in 2003. Here is the section of code...
              Code:
               Dim db As DAO.Database
                  Dim td As DAO.TableDef
                  Dim frm As Form
                  Dim sec, dtl As Section
                  Dim col As DAO.Field
                  Dim intControlType As Integer
                  Dim ctlLabel, ctlData, cmd1, cmd2 As Control
                  Dim intDataXleft, intDataYtop, intDataXwidth As Integer
                  Dim counter As Integer
                  Dim exists As Boolean
                  Dim strTemp, frmName, tblName, colName As String
                  
                  Set db = CurrentDb
              
              Set frm = CreateForm()
                      DoCmd.SelectObject acForm, frm.name, False
                      DoCmd.RunCommand acCmdFormHdrFtr
                      'set properties
                      With frm
                      .RecordSource = tblName
                      .DefaultView = 1
                      .DividingLines = False
                      .RecordSelectors = False
                      frmName = Mid$(tblName, 9, 20)
                      .Caption = frmName
                      .AllowPivotChartView = False
                      .AllowPivotTableView = False
                      .AutoCenter = True
                      .AutoResize = True
                      intDataXleft = 100
                      intDataYtop = 100    
                  
                  For Each col In td.Fields
                              
                      If col.name = "row" Then
                          intDataXwidth = 800
                      Else
                          intDataXwidth = 4500
                      End If
                      
                  Set ctlData = CreateControl(frm.name, acTextBox, , "", col.name, _
                  intDataXleft, intDataYtop, intDataXwidth)
                  ctlData.TextAlign = 1
                  ctlData.name = "ctl" & col.name
                  ctlData.CanGrow = True
              
                  intDataXleft = intDataXleft + intDataXwidth + 100
                  Next col
              
                  End with
                     
                  strTemp = frm.name
                  
                  DoCmd.Save acForm, frm.name
                  DoCmd.close acForm, frm.name, acSaveYes
                  DoCmd.Rename frmName, acForm, strTemp
                  DoCmd.OpenForm frmName, acNormal, , , acFormReadOnly
                  DoEvents
              End If
              
              Set col = Nothing
              Set td = Nothing
              Set db = Nothing
              Last edited by Deekay; Sep 18 '10, 12:20 PM. Reason: whoops - hit yhe send button too early

              Comment

              • Deekay
                New Member
                • May 2010
                • 21

                #8
                I'm working in 2003. Here is the section of code...
                Code:
                Private Function dealWithErrors()
                
                    Dim db As DAO.Database
                    Dim td As DAO.TableDef
                    Dim frm As Form
                    Dim sec, dtl As Section
                    Dim col As DAO.Field
                    Dim intControlType As Integer
                    Dim ctlLabel, ctlData, cmd1, cmd2 As Control
                    Dim intDataXleft, intDataYtop, intDataXwidth As Integer
                    Dim counter As Integer
                    Dim exists As Boolean
                    Dim strTemp, frmName, tblName, colName As String
                    
                    Set db = CurrentDb
                
                Set frm = CreateForm()
                        DoCmd.SelectObject acForm, frm.name, False
                        DoCmd.RunCommand acCmdFormHdrFtr
                        'set properties
                        With frm
                        .RecordSource = tblName
                        .DefaultView = 1
                        .DividingLines = False
                        .RecordSelectors = False
                        frmName = Mid$(tblName, 9, 20)
                        .Caption = frmName
                        .AllowPivotChartView = False
                        .AllowPivotTableView = False
                        .AutoCenter = True
                        .AutoResize = True
                        intDataXleft = 100
                        intDataYtop = 100    
                    
                    For Each col In td.Fields
                                
                        If col.name = "row" Then
                            intDataXwidth = 800
                        Else
                            intDataXwidth = 4500
                        End If
                        
                    Set ctlData = CreateControl(frm.name, acTextBox, , "", col.name, _
                    intDataXleft, intDataYtop, intDataXwidth)
                    ctlData.TextAlign = 1
                    ctlData.name = "ctl" & col.name
                    ctlData.CanGrow = True
                
                    intDataXleft = intDataXleft + intDataXwidth + 100
                    Next col
                
                    End with
                       
                    strTemp = frm.name
                    
                    DoCmd.Save acForm, frm.name
                    DoCmd.close acForm, frm.name, acSaveYes
                    DoCmd.Rename frmName, acForm, strTemp
                    DoCmd.OpenForm frmName, acNormal, , , acFormReadOnly
                    DoEvents
                End If
                
                Set col = Nothing
                Set td = Nothing
                Set db = Nothing
                
                exit_function_DealWithErrors:
                Exit Function
                working in debug mode the error occurs on line 19.

                thanks in advance.

                Comment

                Working...