Results 1 to 1 of 1

Incomplete data is saving in the data base instead of saving complete data

Threaded View

lathish Incomplete data is saving in... 10-31-2013, 02:36 AM
  1. #1
    Registered User
    Join Date
    10-29-2013
    Location
    kozhikode
    MS-Off Ver
    Excel 2007
    Posts
    1

    Incomplete data is saving in the data base instead of saving complete data

    Sir,
    I am new to VBA I will explain my problem, I have created a vba for a user form in which the data I entered should be saved in the data sheet2 viz Sheet("Data").Its working but if I press SUBMIT button incomplete data is also saving in the data sheet.In short I need the code as the data should be saved if and only if all the fields are filled in the user form.Please do make it correct.Here is my code


    Private Sub commandbutton1_click()
    Dim nextrow As Integer
    '=COUNTA(A:A)+1
    nextrow = WorksheetFunction.CountA(Sheets("Data").Range("A:A")) + 1
    Sheets("Data").Cells(nextrow, 1) = Now
    Sheets("Data").Cells(nextrow, 2) = UserForm1.TextBox1.Value
    Sheets("Data").Cells(nextrow, 3) = UserForm1.ComboBox1.Value
    Sheets("Data").Cells(nextrow, 4) = UserForm1.TextBox2.Value
    Sheets("Data").Cells(nextrow, 5) = UserForm1.ComboBox2.Value
    Sheets("Data").Cells(nextrow, 6) = UserForm1.ComboBox3.Value
    Sheets("Data").Cells(nextrow, 7) = UserForm1.ComboBox4.Value
    Sheets("Data").Cells(nextrow, 8) = UserForm1.ComboBox5.Value
    If UserForm1.TextBox1.Value = Empty Then
    MsgBox "Please enter Name.", vbExclamation
    UserForm1.TextBox1.SetFocus
    Exit Sub
    End If
    If UserForm1.ComboBox1.Value = Empty Then
    MsgBox "Please choose Religion.", vbExclamation
    UserForm1.ComboBox1.SetFocus
    Exit Sub
    End If
    If UserForm1.TextBox2.Value = Empty Then
    MsgBox "Please enter Caste.", vbExclamation
    UserForm1.TextBox2.SetFocus
    Exit Sub
    End If
    If UserForm1.ComboBox2.Value = Empty Then
    MsgBox "Please choose Date of Birth.", vbExclamation
    UserForm1.ComboBox2.SetFocus
    Exit Sub
    End If
    If UserForm1.ComboBox3.Value = Empty Then
    MsgBox "Please choose Month.", vbExclamation
    UserForm1.ComboBox3.SetFocus
    Exit Sub
    End If
    If UserForm1.ComboBox4.Value = Empty Then
    MsgBox "Please choose Year.", vbExclamation
    UserForm1.ComboBox4.SetFocus
    Exit Sub
    End If
    If UserForm1.ComboBox5.Value = Empty Then
    MsgBox "Please choose Gender.", vbExclamation
    UserForm1.ComboBox5.SetFocus
    Exit Sub
    End If
    Unload UserForm1
    End Sub
    
    Private Sub commandbutton2_click()
    Unload UserForm1
    End Sub
    
    Private Sub userform_Activate()
    Dim i As Integer
    Dim c As Integer
    Dim k As Integer
    Dim Religion As String
    Dim Gender As String
    For i = 1 To 31
    UserForm1.ComboBox2.AddItem i
    Next i
    For c = 1 To 12
    UserForm1.ComboBox3.AddItem c
    Next c
    For k = 1970 To 2050
    UserForm1.ComboBox4.AddItem k
    Next k
    UserForm1.ComboBox1.AddItem "Hindu"
    UserForm1.ComboBox1.AddItem "Christian"
    UserForm1.ComboBox1.AddItem "Muslim"
    UserForm1.ComboBox5.AddItem "Male"
    UserForm1.ComboBox5.AddItem "Female"
    End Sub
    Private Sub combobox2_keypress(ByVal keyascii As MSForms.ReturnInteger)
    keyascii = 0
    End Sub
    Private Sub combobox3_keypress(ByVal keyascii As MSForms.ReturnInteger)
    keyascii = 0
    End Sub
    Private Sub combobox4_keypress(ByVal keyascii As MSForms.ReturnInteger)
    keyascii = 0
    End Sub
    Private Sub combobox5_keypress(ByVal keyascii As MSForms.ReturnInteger)
    keyascii = 0
    End Sub
    Moderator Note:

    Pls use code tags around your code next time as per forum rules.
    Last edited by Fotis1991; 10-31-2013 at 03:05 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Saving external links without saving data values
    By john@axiomatix in forum Excel General
    Replies: 2
    Last Post: 06-18-2013, 05:58 AM
  2. Replies: 1
    Last Post: 05-04-2013, 06:42 PM
  3. Require a return of Complete or incomplete base on information in a cell
    By ROB40160 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-12-2012, 11:17 AM
  4. Replies: 6
    Last Post: 09-01-2010, 11:09 AM
  5. Comparing complete with incomplete years data
    By akhlaq768 in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 09-10-2008, 08:04 AM

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