Results 1 to 6 of 6

Thread: [2005] popping up message wen forgotten to insert details

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    58

    [2005] popping up message wen forgotten to insert details

    i want, when i forgot to insert the details in one of the fields, there will be a pop up error but the thing is, i did not know how to do the codes. can someone give me the codes??? plzzz

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] popping up message wen forgotten to insert details

    What field? When do you want this message to appear?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    58

    Re: [2005] popping up message wen forgotten to insert details

    a form that contains 2 textboxes and 1 button that say Add button. when the user did not attempt to two textboxes and just click on the Add button, there will be an error saying that ("You have to attempt all the textboxes"). what codes shud i do? can pass me the codes??

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] popping up message wen forgotten to insert details

    You want to do something when the user clicks a button then handle its Click event. In the event handler test the Text property of each TextBox to make sure its a valid value. I usually test for at least one non-whitespace character:
    VB Code:
    1. If Me.TextBox1.Text.Trim() = String.Empty Then
    2.     'The field is empty so display an error message.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    58

    Re: [2005] popping up message wen forgotten to insert details

    where shud i put that code into my code since my code looks like this :

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim cmd As New OleDb.OleDbCommand

    Dim strsql As String
    con = New OleDb.OleDbConnection(strcon)
    con.Open()

    strsql = "Insert into item(ItemId,ItemTitle,ItemCategory,ItemClassification,Status,AuthorName,DateOfPublished,DateCreated, CostPriceOfItem,PublisherName,ReferenceNo,Edition,DateUpdated) values('" & TextBox1.Text & "',' " & TextBox3.Text & "',' " & ComboBox2.Text & "','" & ComboBox3.Text & "',' " & ComboBox1.Text & "','" & TextBox4.Text & "',' " & TextBox5.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox6.Text & "','" & TextBox2.Text & "','" & TextBox10.Text & "','" & Format(DateTimePicker1.Value) & "')"
    cmd.Connection = con
    cmd.CommandText = strsql
    cmd.ExecuteNonQuery()

    con.Close()

    MsgBox("Successfully Adding Record!")
    Me.Close()

    End Sub

    do help me will you?? please

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] popping up message wen forgotten to insert details

    Think about when you want it to happen. You need it to happen when the user clicks the button, so obviously it has to go in the button's Click event handler, which I already stated in my previous post. Now, do you think you should test the fields before or after saving the record to the database? Not much point doing it after is there? You check the fields and if one is empty then you display the error message, otherwise you save the record.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width