+ Reply to Thread
Results 1 to 6 of 6

Data Entry Form Inserting New Row Outside of Table

Hybrid View

  1. #1
    Registered User
    Join Date
    04-23-2019
    Location
    Pittsburgh, PA
    MS-Off Ver
    MS Office 365
    Posts
    7

    Question Data Entry Form Inserting New Row Outside of Table

    Hello!

    I've created a Data Entry form that I want to insert a new row at the top of of a table.

    The code I'm using was copied from another site and, while it is indeed adding a new row, it's doing so in the cells below the table instead of inside which is negating the table formatting altogether.

    I'm hoping you can help me change this code to operate as such. I'll attach screenshots to hopefully better illustrate what I'm looking to do.

    Thanks!

    Private Sub cmdAdd_Click()
        'Copy input values to sheet.
        Dim IRow As Long
        Dim ws As Worksheet
        Set ws = Projects
    
        IRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        With ws
            .Cells(IRow, 1).Value = Me.txtJobNumber.Value
            .Cells(IRow, 2).Value = Me.txtProjectName.Value
            .Cells(IRow, 3).Value = Me.txtDueDate.Value
            .Cells(IRow, 4).Value = Me.cboStatus.Value
            .Cells(IRow, 6).Value = Me.txtClientName.Value
            .Cells(IRow, 7).Value = Me.txtAddress.Value
            .Cells(IRow, 8).Value = Me.txtCity.Value
            .Cells(IRow, 9).Value = Me.txtState.Value
            .Cells(IRow, 10).Value = Me.txtZip.Value
            .Cells(IRow, 11).Value = Me.txtCounty.Value
            .Cells(IRow, 12).Value = Me.txtProjState.Value
            .Cells(IRow, 13).Value = Me.txtJobDescription.Value
            .Cells(IRow, 14).Value = Me.cboEngineer.Value
            .Cells(IRow, 15).Value = Me.cboSurvey.Value
            .Cells(IRow, 16).Value = Me.cboDraftsman.Value
    
        End With
    Capture.PNG
    Last edited by Niccii; 04-24-2019 at 03:13 PM. Reason: Added Images

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Data Entry Form Inserting New Row Outside of Table

    Hi Niccii

    I want to insert a new row at the top of of a table.
    You have not uploaded a sample file but this will give you an idea...
    Option Explicit
    
    Sub AddToFirstRowofTable()
    Dim ws As Worksheet
    Set ws = Sheets("Projects")
    With ws
      With .ListObjects("Table1") ' Change Table1 to name of your table
        .ListRows.Add (1) ' the (1) depicts first row
        .DataBodyRange(1, 1) = " NewValue1"
        .DataBodyRange(1, 2) = " NewValue2"
        '.DataBodyRange(1, 1).Resize(, 2) = Array("NewValue1", "NewValue2") 'or this can be used to populate above two values
      End With
    End With
    End Sub
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    04-23-2019
    Location
    Pittsburgh, PA
    MS-Off Ver
    MS Office 365
    Posts
    7

    Re: Data Entry Form Inserting New Row Outside of Table

    Sintek, how silly of me, I hadn't thought to connect the workbook!

    I've attached it now if you'd like to take a look at it.
    (At least I tried to, it won't let me post it until I've made a few posts)

    I did attempt to add your code, but I'm not entirely sure how to make it fit in with the cmdAdd_Click code.

    I tend to overreach for my skill set, but I guess that's how we learn, right?

    Private Sub cboStatus_DropButtonClick()
        'Populate control.
        Me.cboStatus.AddItem "New Project"
        Me.cboStatus.AddItem "In Survey"
        Me.cboStatus.AddItem "On Deck"
        Me.cboStatus.AddItem "In Work"
        Me.cboStatus.AddItem "In Review"
        Me.cboStatus.AddItem "In Engineering"
        Me.cboStatus.AddItem "CANCELLED"
        
    End Sub
    Private Sub cboEngineer_DropButtonClick()
        'Populate control.
        Me.cboEngineer.AddItem "BL"
        Me.cboEngineer.AddItem "DL"
        Me.cboEngineer.AddItem "JB"
        Me.cboEngineer.AddItem "JH"
        Me.cboEngineer.AddItem "LM"
        Me.cboEngineer.AddItem "SC"
        Me.cboEngineer.AddItem "SM"
        Me.cboEngineer.AddItem "SO"
    
    End Sub
    Private Sub cboDraftsman_DropButtonClick()
        'Populate control.
        Me.cboDraftsman.AddItem "ED"
        Me.cboDraftsman.AddItem "LRH"
        Me.cboDraftsman.AddItem "MP"
        
    End Sub
    Private Sub cboSurvey_DropButtonClick()
        'Populate control.
        Me.cboSurvey.AddItem "AR"
        Me.cboSurvey.AddItem "DL"
        Me.cboSurvey.AddItem "JL"
        Me.cboSurvey.AddItem "MP"
        
    End Sub
    
    Private Sub cmdAdd_Click()
        'Copy input values to sheet.
        Dim IRow As Long
        Dim ws As Worksheet
        Set ws = Projects
    
        IRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        With ws
        .Cells(IRow, 1).Value = Me.txtJobNumber.Value
        .Cells(IRow, 2).Value = Me.txtProjectName.Value
        .Cells(IRow, 3).Value = Me.txtDueDate.Value
        .Cells(IRow, 4).Value = Me.cboStatus.Value
        .Cells(IRow, 6).Value = Me.txtClientName.Value
        .Cells(IRow, 7).Value = Me.txtAddress.Value
        .Cells(IRow, 8).Value = Me.txtCity.Value
        .Cells(IRow, 9).Value = Me.txtState.Value
        .Cells(IRow, 10).Value = Me.txtZip.Value
        .Cells(IRow, 11).Value = Me.txtCounty.Value
        .Cells(IRow, 12).Value = Me.txtProjState.Value
        .Cells(IRow, 13).Value = Me.txtJobDescription.Value
        .Cells(IRow, 14).Value = Me.cboEngineer.Value
        .Cells(IRow, 15).Value = Me.cboSurvey.Value
        .Cells(IRow, 16).Value = Me.cboDraftsman.Value
        End With
        
        'Clear input controls.
        Me.cboStatus.Value = ""
        Me.txtJobNumber.Value = ""
        Me.txtProjectName.Value = ""
        Me.txtDueDate.Value = ""
        Me.txtClientName.Value = ""
        Me.txtAddress.Value = ""
        Me.txtCity.Value = ""
        Me.txtState.Value = ""
        Me.txtZip.Value = ""
        Me.txtCounty.Value = ""
        Me.txtProjState.Value = ""
        Me.cboEngineer.Value = ""
        Me.cboSurvey.Value = ""
        Me.cboDraftsman.Value = ""
        Me.txtJobDescription.Value = ""
            
    End Sub
    Private Sub cmdClose_Click()
        'Close UserForm.
        Unload Me
        
    End Sub
    
    Private Sub Label1_Click()
    
    End Sub

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Data Entry Form Inserting New Row Outside of Table

    Private Sub cmdAdd_Click()
    Dim ws As Worksheet
    Set ws = Sheets("Project Tracking")
    With ws
        With .ListObjects("Table1")
            .ListRows.Add (1)
            .DataBodyRange(1, 1) = Me.txtJobNumber.Value
            .DataBodyRange(1, 2) = Me.txtJobNumber.Value
            'etc for rest of columns
        End With
    End With
    End Sub

  5. #5
    Registered User
    Join Date
    04-23-2019
    Location
    Pittsburgh, PA
    MS-Off Ver
    MS Office 365
    Posts
    7

    Re: Data Entry Form Inserting New Row Outside of Table

    Hmm, it's still not adding at the top of the checklist, so the data set is listed backwards to what I'd prefer... it may just work for the time being. I'm not sure how much I want to fight it.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Data Entry Form Inserting New Row Outside of Table

    What do you mean...
    Hmm, it's still not adding at the top of the checklist
    What checklist...
    Explain in detail where you want the data to be added...Perhaps you should upload a before and after sheet with your expected results depicted...
    The code provided will add your new data to row 3 of your Table...every time you press the button
    Last edited by sintek; 04-26-2019 at 02:42 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Data entry form to populate certain table dependent on validation list
    By nmorrow in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-10-2017, 05:22 AM
  2. [SOLVED] Help with custom data entry form with dropdown lists populated by table columns...
    By gaz1man in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2014, 01:28 PM
  3. Inserting a table in an excel form
    By andrete in forum Excel General
    Replies: 1
    Last Post: 02-08-2014, 11:30 AM
  4. [SOLVED] HELP: Inserting a drop down box into a Data Entry Form
    By mwinter in forum Excel General
    Replies: 12
    Last Post: 12-18-2013, 03:32 PM
  5. Replies: 2
    Last Post: 06-07-2013, 09:08 AM
  6. Date capture in Entry Form to Data Table
    By JIBG in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-02-2007, 09:14 PM
  7. Data Entry Form (similar to default Excel Data>Form)
    By tonydm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-11-2005, 02:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1