+ Reply to Thread
Results 1 to 6 of 6

user form overlabps the records if one field is not filled

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    user form overlabps the records if one field is not filled

    Hello members!

    My worksheet with user form is here. if I start entering first record and I leave one field(suppose Sr.No) empty for the first record and when I enter the second record with Sr. No. it overlaps my first record.Your kind suggestions are needed.

    Best Regards
    Bhatti
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: user form overlabps the records if one field is not filled

    It is because it search for first empty row in column A. When you don't populate Sr.No then the cell in column A is empty and it overwrites the last record.
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: user form overlabps the records if one field is not filled

    So how to make it search first empty range instead. So that if we dont fill a filed in one record it should not mix the second record with the previous one? My code is given below:
    Private Sub cmdAdd_Click()
    Dim lngWriteRow As Long

    Dim ws As Worksheet
    Set ws = Worksheets("MainTable")

    lngWriteRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row

    ws.Range("a" & lngWriteRow) = txtSrNo.Value
    ws.Range("b" & lngWriteRow) = txtAdmnDate.Value
    ws.Range("c" & lngWriteRow) = txtAdmnNo.Value
    ws.Range("d" & lngWriteRow) = txtAppDate.Value
    ws.Range("e" & lngWriteRow) = txtName.Value
    ws.Range("f" & lngWriteRow) = txtDOB.Value
    ws.Range("g" & lngWriteRow) = CBReligion.Value
    ws.Range("h" & lngWriteRow) = CBCat.Value
    ws.Range("i" & lngWriteRow) = CBServingCat.Value
    ws.Range("j" & lngWriteRow) = txtFName.Value
    ws.Range("k" & lngWriteRow) = txtAddress.Value
    ws.Range("l" & lngWriteRow) = txtMob.Value
    ws.Range("n" & lngWriteRow) = CBClass.Value
    ws.Range("o" & lngWriteRow) = CBSection.Value
    ws.Range("p" & lngWriteRow) = CBChildNo.Value
    ws.Range("q" & lngWriteRow) = txtSLCdate.Value
    ws.Range("r" & lngWriteRow) = txtSLCNo.Value
    ws.Range("s" & lngWriteRow) = CBCurrStatus.Value

    Dim Wingchoice As String
    If Me.OBJNRWing Then
    Wingchoice = "JNR Wing"
    ElseIf Me.OBMidWing Then
    Wingchoice = "Middle Wing"
    ElseIf Me.OBSnrWing Then
    Wingchoice = "SNR Wing"
    Else
    Wingchoice = ""
    End If
    ws.Range("m" & lngWriteRow).Value = Wingchoice

    End Sub


    Private Sub cmdClr_Click()

    txtSrNo.Value = ""
    txtAdmnDate.Value = ""
    txtAdmnNo.Value = ""
    txtAppDate.Value = ""
    txtName.Value = ""
    txtDOB.Value = ""
    CBReligion.Value = ""
    CBCat.Value = ""
    CBServingCat.Value = ""
    txtFName.Value = ""
    txtAddress.Value = ""
    txtMob.Value = ""
    CBClass.Value = ""
    CBSection.Value = ""
    CBChildNo.Value = ""
    txtSLCdate.Value = ""
    txtSLCNo.Value = ""
    CBCurrStatus.Value = ""

    End Sub
    Private Sub cmdQuit_Click()
    Unload FrmData
    End Sub
    Private Sub CBClass_Change()
    Me.CBSection = ""

    Select Case Me.CBClass
    Case "One"
    Me.CBSection.RowSource = "One"
    Case "Two"
    Me.CBSection.RowSource = "Two"
    Case "Three"
    Me.CBSection.RowSource = "Three"
    Case "Four"
    Me.CBSection.RowSource = "Four"
    Case "Five"
    Me.CBSection.RowSource = "Five"
    Case "Six"
    Me.CBSection.RowSource = "Six"
    Case "Seven"
    Me.CBSection.RowSource = "Seven"
    Case "Eight"
    Me.CBSection.RowSource = "Eight"
    Case "Nine"
    Me.CBSection.RowSource = "Nine"
    Case "Ten"
    Me.CBSection.RowSource = "Ten"

    Case Else
    'do nothing
    End Select
    End Sub

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: user form overlabps the records if one field is not filled

    it's up to you to decide which field is required and will always present. Change following line of code

    Please Login or Register  to view this content.
    change number marked in red to match respective column, i.e. 1=A, 2=B, etc.

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,631

    Re: user form overlabps the records if one field is not filled

    @ Excelisfun

    Please use code tags (#) instead of quotes; it makes the post smaller and the thread readable

  6. #6
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: user form overlabps the records if one field is not filled

    Thanks buran . this is what I wanted.but beside this I did another change to the code
    Please Login or Register  to view this content.

+ 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. Preserving User Form Records for each entry
    By henryBukowski in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2015, 06:53 AM
  2. Combobox is not filled when user form is initialised
    By methuselah90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2014, 08:12 PM
  3. VBA User Form Check all Fields Filled Combo box
    By JSmith1504 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2014, 10:55 AM
  4. Search for/Edit Records with a User Form
    By LONeill13 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2013, 03:24 PM
  5. Generate a new worksheet each time a user form is filled out
    By brandoom989 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-18-2012, 03:40 PM
  6. Update records in a worksheet using a user form
    By crashhold in forum Excel General
    Replies: 3
    Last Post: 05-06-2011, 10:15 PM
  7. user form to add records to rows
    By jcarstens in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-24-2009, 10:11 PM

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