First, sorry for my bad english!
I want to make an userform which checks if there are empty textboxes. For some textbox it tells you to fill them and for others it just notifies you that you have left them blank.
What I want to do:
1. Tells that ISBN, nimi, kirjoittaja, julkaisuvuosi can not be left blank
2. If there are other blank textboxes it asks if you want to continue anyway. If the answer is yes it will print the data to the database otherwise it gives you the opportunity to fill in the empty textboxes
Here's what I have gotten so far
- Code: Select all
Private Sub CommandButton1_Click()
Dim sheet1 As Worksheet
Set sheet1 = ThisWorkbook.Sheets("Tietokanta")
nr = sheet1.Cells(Rows.Count, 1).End(xlUp).Row + 1
If ISBN.Value = "" Then
MsgBox "ISBN:ää ei voi jättää tyhjäksi", vbExclamation, "Input Data"
ISBN.SetFocus
Exit Sub
End If
If nimi.Value = "" Then
MsgBox "Kirjan nimeä ei voi jättää tyhjäksi", vbExclamation, "Input Data"
nimi.SetFocus
Exit Sub
End If
If kirjoittaja.Value = "" Then
MsgBox "kirjoittajaa ei voi jättää tyhjäksi", vbExclamation, "Input Data"
ISBN.SetFocus
Exit Sub
End If
If julkaisuvuosi.Value = "" Then
MsgBox "julkaisuvuotta ei voi jättää tyhjäksi", vbExclamation, "Input Data"
ISBN.SetFocus
Exit Sub
End If
sheet1.Cells(nr, 1) = ISBN.Text
sheet1.Cells(nr, 2) = nimi.Text
sheet1.Cells(nr, 3) = kirjoittaja.Text
sheet1.Cells(nr, 4) = kustantaja.Text
sheet1.Cells(nr, 5) = genre.Text
sheet1.Cells(nr, 6) = julkaisuvuosi.Text
sheet1.Cells(nr, 7) = kieli.Text
sheet1.Cells(nr, 8) = kansityyppi.Text
sheet1.Cells(nr, 9) = "lainattavissa"
sheet1.Cells(nr, 10) = Date
Unload UserForm1
End Sub