+ Reply to Thread
Results 1 to 10 of 10

User Form adding records in 2 rows at a time

Hybrid View

  1. #1
    Registered User
    Join Date
    01-24-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: User Form adding records in 2 rows at a time

    Private Sub cmdAdd_Click()
     Dim lRow As Long
     Dim lPart As Long
     Dim ws As Worksheet
     Set ws = Worksheets("PartsData")
     
    'find first empty row in database
     ''lRow = ws.Cells(Rows.Count, 1) _
     '' .End(xlUp).Offset(1, 0).Row
     
    'revised code to avoid problems with
     'Excel lists and tables in newer versions
     lRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
     SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
     lPart = Me.cboPart.ListIndex
     
    'check for a part number
     If Trim(Me.cboPart.Value) = "" Then
     Me.cboPart.SetFocus
     MsgBox "Please enter a part number"
     End If
     If Trim(Me.cboLocation.Value) = "" Then
     Me.cboLocation.SetFocus
     MsgBox "Please enter the Location"
     Exit Sub
     End If
     
    'copy the data to the database
     With ws
     .Cells(lRow, 1).Value = Me.txtDate.Value
     .Cells(lRow, 2).Value = Me.cboLocation.Value
     .Cells(lRow, 4).Value = Me.cboPart.Value
     .Cells(lRow, 5).Value = Me.cboPart.List(lPart, 1)
     .Cells(lRow, 9).Value = Me.txtQty.Value
     .Cells(lRow, 11).Value = Me.txtQty2.Value
     .Cells(lRow, 7).Value = Me.txtQty3.Value
     .Cells(lRow, 8).Value = Me.txtQty4.Value
     'new addition
    
    
     End With
     
    'clear the data
     Me.cboPart.Value = ""
     Me.cboLocation.Value = ""
     Me.cboLocation2.Value = ""
     Me.txtDate.Value = Format(Date, "Medium Date")
     Me.txtQty.Value = ""
     Me.cboPart.SetFocus
     
    End Sub

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: User Form adding records in 2 rows at a time

    Hi Misbah

    Perfect.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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