hello everyone i need help about msgbox "Insufficient Data" coding.
below is my coding:

Private Sub cmdSave_Click()

On Error Resume Next

Adodc1.Recordset.AddNew

Adodc1.Recordset!Dateregistration = txtDate.Text
Adodc1.Recordset!Title = cmbTitle.Text
Adodc1.Recordset!Name = txtName.Text
Adodc1.Recordset!Ic = txtIc.Text
Adodc1.Recordset!Email = txtEmail.Text
Adodc1.Recordset!Phonenumber = txtPhone.Text
Adodc1.Recordset!Address = txtAddress.Text
Adodc1.Recordset!Address1 = txtAddress1.Text
Adodc1.Recordset!Residential = cmbResidential.Text
Adodc1.Recordset!Gender = cmbGender.Text
Adodc1.Recordset!Numberofrooms = cmbNumber.Text
Adodc1.Recordset!Rentalprices = txtRental.Text

Adodc1.Recordset.Update
MsgBox "Successfuly Save!!!", vbInformation

End Sub

im using adodc connection:

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\sistempengurusanrumahsewa.mdb;Persist Security Info=False"
Adodc1.RecordSource = "Select * from owner"
Set DataGrid1.DataSource = Adodc1
End Sub

my main problem is how to add msgbox "Insufficient Data" if a field is empty??
thanks.

Recommended Answers

All 8 Replies

well you can add

if txtDate.text = "" or cmbtitle.text = "" or txtName.text = "" or txtIc.text = "" or txtEmail.text = "" or txtPhone.text = "" or txtAddress.text = "" or txtAddress1.text = "" or txtResidential.text = "" or cmbGender.text = "" or cmbNumber.text = "" or txtRental.text = "" then

Msgbox("Please fill up all the requirement fields")
else
Adodc1.Recordset.Update
MsgBox "Successfuly Save!!!", vbInformation
end if


try to replece your line 20 up to line 24 with this code

well you can add

if txtDate.text = "" or cmbtitle.text = "" or txtName.text = "" or txtIc.text = "" or txtEmail.text = "" or txtPhone.text = "" or txtAddress.text = "" or txtAddress1.text = "" or txtResidential.text = "" or cmbGender.text = "" or cmbNumber.text = "" or txtRental.text = "" then

Msgbox("Please fill up all the requirement fields")
else
Adodc1.Recordset.Update
MsgBox "Successfuly Save!!!", vbInformation
end if


try to replece your line 20 up to line 24 with this code
the or in the if else means if he meet even one of the requirement of the field he will display the "Please fill up...."

hello xtianenikkian,
it doesnt work.
it doesnt show successfuly save.
it stills save into my database although the fields are empty.

:(

Try this.

Private Sub cmdSave_Click()

On Error Resume Next


If txtDate.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtDate.SetFocus: Exit Sub
If cmbTitle.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbTitle.SetFocus: Exit Sub
If txtName.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtName.SetFocus: Exit Sub
If txtIc.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtIc.SetFocus: Exit Sub
If txtEmail.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtEmail.SetFocus: Exit Sub
If txtPhone.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtPhone.SetFocus: Exit Sub
If txtAddress.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtAddress.SetFocus: Exit Sub
If txtAddress1.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtAddress1.SetFocus: Exit Sub
If cmbResidential.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbResidential.SetFocus: Exit Sub
If cmbGender.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbGender.SetFocus: Exit Sub
If cmbNumber.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbNumber.SetFocus: Exit Sub
If txtRental.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtRental.SetFocus: Exit Sub



Adodc1.Recordset.AddNew

Adodc1.Recordset!Dateregistration = txtDate.Text
Adodc1.Recordset!Title = cmbTitle.Text
Adodc1.Recordset!Name = txtName.Text
Adodc1.Recordset!Ic = txtIc.Text
Adodc1.Recordset!Email = txtEmail.Text
Adodc1.Recordset!Phonenumber = txtPhone.Text
Adodc1.Recordset!Address = txtAddress.Text
Adodc1.Recordset!Address1 = txtAddress1.Text
Adodc1.Recordset!Residential = cmbResidential.Text
Adodc1.Recordset!Gender = cmbGender.Text
Adodc1.Recordset!Numberofrooms = cmbNumber.Text
Adodc1.Recordset!Rentalprices = txtRental.Text

Adodc1.Recordset.Update
MsgBox "Successfuly Save!!!", vbInformation

End Sub

You can change the message for each entity, such as for txtEmail,

the message can be "Field empty. Please Enter Email address!"

There is a much quicker way to solve this. For all the other postes, please note that it is a bad habit of coding by using the "" quotemarks to refer to an empty string. VB uses the vbNullstring in confirming an empty string -

'As incorrect ----
Text1.Text = ""

'As Correct -----
Text1.Text = vbNullString

To check if all textboxes contains text, the following in a module -

Public Sub CheckStringAdded (frm As Form)
Dim MyTextbox As Control

 For Each MyTextbox In frm.Controls
        If TypeOf Control Is TextBox Then
            If MyTextbox.Text = vbNullString Then
               Msgbox "No Text added", vbOkOnly + vbExclamation, "No Text"
            
               MyTextbox.Setfocus
               Exit Sub
            End IF
        End If
       
    Next Control
End Sub

'In your form call it as ....

Call CheckStringAdded (Me)

thanks abelingaw n AndreRet, u both are genius! it solved my problem.
:)

It was a pleasure. Now all you have to do is to mark this thread as solved, found at the bottom of this post, thanks.:)

okay thanks. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.