'

Private Sub department()
Dim dep As String
dep = Trim(Adoaddlec.Recordset.Fields("department"))
    If (dep = "1") Then
        optict.Value = True
        ElseIf (dep = "2") Then
            optassessmentprogramme.Value = True
        ElseIf (dep = "3") Then
            optdbt.Value = True
        ElseIf (dep = "4") Then
            opttvet.Value = True
        ElseIf (dep = "5") Then
            optcarrerdev.Value = True
        ElseIf (dep = "6") Then
        optictinstruc.Value = True
        ElseIf (dep = "7") Then
            opteventsmanagement.Value = True
        ElseIf (dep = "8") Then
            opteduandtranng.Value = True
        ElseIf (dep = "9") Then
            optcnstrudsitemanagement.Value = True
    End If
End Sub

my problem is getting the values to store in the database please help

Recommended Answers

All 11 Replies

Do the reverse of what you are doing...

Do the reverse of what you are doing...

do wat exactly?

If optict.Value = True Then
  Adoaddlec.Recordset.Fields("department") = "1"
...
If optict.Value = True Then
  Adoaddlec.Recordset.Fields("department") = "1"
...

that didn't seem to be the problem here the entire code i types

Private Sub cmdsave_Click()
Dim street As String
street = txtstreet.Text

If (txtlname.Text = "") Then
MsgBox "Last Name is compulsory", vbExclamation + vbOKOnly, "Atmoic Inc"
txtlname.SetFocus

ElseIf (txtfname.Text = "") Then
MsgBox "First Name is compulsory", vbExclamation + vbOKOnly, "Atmoic Inc"
txtfname.SetFocus
ElseIf (optftime.Value = False) And (optptime.Value = False) Then
MsgBox "Please select your status", vbExclamation + vbOKOnly, "Atmoic Inc"
ElseIf (cboparish.Text = "Select Parish") Then
MsgBox "Please select a parish", vbExclamation + vbOKOnly, "Error"
ElseIf (street = "") Then
MsgBox "Street should contain a street address", vbExclamation + vbOKOnly, "Atmoic Inc"
ElseIf (txtphoneno.Text = "") And (txtcellno.Text = "") Then
MsgBox "Work and Cell number is compulsory", vbInformation + vbOKOnly, "Atomic Inc"
ElseIf (optict.Value = False) And (optassessmentprogramme.Value = False) And (optdbt.Value = False) And (opttvet.Value = False) And (optcarrerdev.Value = False) And (optictinstruc.Value = False) And (opteventsmanagement.Value = False) And (opteduandtranng.Value = False) And (optcnstrudsitemanagement.Value = False) Then
MsgBox "Please select your respective department", vbQuestion + vbOKOnly, "Atomic Inc"
Else
If (optftime.Value = True) Then
Adoaddlec.Recordset.Fields("status") = "ft"
ElseIf (optptime.Value = True) Then
Adoaddlec.Recordset.Fields("status") = "pt"
ElseIf (cboparish.Text = "Clarendon") Then
Adoaddlec.Recordset.Fields("parish") = 1
ElseIf (cboparish.Text = "Hanover") Then
Adoaddlec.Recordset.Fields("parish") = 2
ElseIf (cboparish.Text = "Manchester") Then
Adoaddlec.Recordset.Fields("parish") = 3
ElseIf (cboparish.Text = "Portland") Then
Adoaddlec.Recordset.Fields("parish") = 4
ElseIf (cboparish.Text = "St.Andrew") Then
Adoaddlec.Recordset.Fields("parish") = 5
ElseIf (cboparish.Text = "St.Ann") Then
Adoaddlec.Recordset.Fields("parish") = 6
ElseIf (cboparish.Text = "St.Catherine") Then
Adoaddlec.Recordset.Fields("parish") = 7
ElseIf (cboparish.Text = "St.Elizabeth") Then
Adoaddlec.Recordset.Fields("parish") = 8
ElseIf (cboparish.Text = "St.James") Then
Adoaddlec.Recordset.Fields("parish") = 9
ElseIf (cboparish.Text = "St.Mary") Then
Adoaddlec.Recordset.Fields("parish") = 10
ElseIf (cboparish.Text = "St.Thomas") Then
Adoaddlec.Recordset.Fields("parish") = 11
ElseIf (cboparish.Text = "Trelwany") Then
Adoaddlec.Recordset.Fields("parish") = 12
ElseIf (cboparish.Text = "Westmoreland") Then
Adoaddlec.Recordset.Fields("parish") = 13
ElseIf (optict.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 1
ElseIf (optassessmentprogramme.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 2
ElseIf (optdbt.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 3
ElseIf (opttvet.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 4
ElseIf (optcarrerdev.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 5
ElseIf (optictinstruc.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 6
ElseIf (opteventsmanagement.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 7
ElseIf (opteduandtranng.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 8
ElseIf (optcnstrudsitemanagement.Value = True) Then
Adoaddlec.Recordset.Fields("department") = 9
End If
Adoaddlec.Recordset.Update
MsgBox "Record Updates", , "Atomic Inc"
End If
End Sub

Private Sub Form_Load()
Call status
Call department
Call parish
End Sub
Private Sub status()
Dim stat_us As String
stat_us = Trim(Adoaddlec.Recordset.Fields("status"))
If (stat_us = "ft") Then
optftime.Value = True
ElseIf (stat_us = "pt") Then
optptime.Value = True
End If
End Sub

Private Sub department()
Dim dep As Variant
dep = Trim(Adoaddlec.Recordset.Fields("department"))
If (dep = 1) Then
optict.Value = True
ElseIf (dep = 2) Then
optassessmentprogramme.Value = True
ElseIf (dep = 3) Then
optdbt.Value = True
ElseIf (dep = 4) Then
opttvet.Value = True
ElseIf (dep = 5) Then
optcarrerdev.Value = True
ElseIf (dep = 6) Then
optictinstruc.Value = True
ElseIf (dep = 7) Then
opteventsmanagement.Value = True
ElseIf (dep = 8) Then
opteduandtranng.Value = True
ElseIf (dep = 9) Then
optcnstrudsitemanagement.Value = True
End If
End Sub


Private Sub parish()
Dim par As Variant
par = Trim(Adoaddlec.Recordset.Fields("parish"))
If (par = 1) Then
cboparish.Text = "Clarendon"
ElseIf (par = 2) Then
cboparish.Text = "Hanover"
ElseIf (par = 3) Then
cboparish.Text = "Manchester"
ElseIf (par = 4) Then
cboparish.Text = "Portland"
ElseIf (par = 5) Then
cboparish.Text = "St.Andrew"
ElseIf (par = 6) Then
cboparish.Text = "St.Ann"
ElseIf (par = 7) Then
cboparish.Text = "St.Catherine"
ElseIf (par = 8) Then
cboparish.Text = "St.Elizabeth"
ElseIf (par = 9) Then
cboparish.Text = "St.James"
ElseIf (par = 10) Then
cboparish.Text = "St.Mary"
ElseIf (par = 11) Then
cboparish.Text = "St.Thomas"
ElseIf (par = 12) Then
cboparish.Text = "Trelwany"
ElseIf (par = 13) Then
cboparish.Text = "Westmoreland"
End If
End Sub

Private Sub cmdsave_Click()
Dim street As String
street = txtstreet.Text

If (txtlname.Text = "") Then
  MsgBox "Last Name is compulsory", vbExclamation + vbOKOnly, "Atmoic Inc"
  txtlname.SetFocus
  [b]Exit Sub[/B]
ElseIf (txtfname.Text = "") Then
  MsgBox "First Name is compulsory", vbExclamation + vbOKOnly, "Atmoic Inc"
  txtfname.SetFocus
  [b]Exit Sub[/B]
...

If any condition fails you need to exit the sub to allow the user to enter the information.

I also do not see a

Adoaddlec.Edit

anywhere

I would think that you would want to evaluate your controls PRIOR to updating/appending records to your database. Meaning, evaluate your controls first, then when you know that they all contain valid values do your .Edit, .Field = value, .Update.

Good Luck

i am using if clauses to check those? wouldn't those be sufficient?

i am planning on doing the edit on another form . and i placed the exit sub but after that my save button won't work it checked everything the way i had it before just not after i placed the exit sub is there a way i could mail you the forms and database etc?

check your personal messages

Private Sub cmdadd_Click()
    optftime.Value = False
    optptime.Value = False
    optict.Value = False
    optassessmentprogramme.Value = False
    optdbt.Value = False
    opttvet.Value = False
    optcarrerdev.Value = False
    optictinstruc.Value = False
    opteventsmanagement.Value = False
    opteduandtranng.Value = False
    optcnstrudsitemanagement.Value = False
    cboparish.Text = "Select Parish"
    
    Adoaddlec.Recordset.AddNew
    txtlname.SetFocus
End Sub

Private Sub cmdexit_Click()
Unload Me
End Sub

Private Sub cmdnext_Click()
Adoaddlec.Recordset.MoveNext
    If (Adoaddlec.Recordset.EOF = True) Then
        Adoaddlec.Recordset.MoveLast
        MsgBox "You are at the last record in the database", vbInformation + vbOKOnly, "Atmoic Inc"
    End If
    Call status
    Call department
    Call parish
End Sub

Private Sub cmdprevious_Click()
Adoaddlec.Recordset.MovePrevious
    If (Adoaddlec.Recordset.BOF = True) Then
        Adoaddlec.Recordset.MoveFirst
        MsgBox " You are at the first record in the database", vbInformation + vbOKOnly, "Atmoic Inc"
    End If
    Call status
    Call department
    Call parish
End Sub

Private Sub cmdsave_Click()
Dim street As String

If (txtlname.Text = "") Then
        MsgBox "Last Name is compulsory", vbExclamation + vbOKOnly, "Atmoic Inc"
        txtlname.SetFocus
   
    ElseIf (txtfname.Text = "") Then
        MsgBox "First Name is compulsory", vbExclamation + vbOKOnly, "Atmoic Inc"
        txtfname.SetFocus
    
    ElseIf (optftime.Value = False) And (optptime.Value = False) Then
        MsgBox "Please select your status", vbExclamation + vbOKOnly, "Atmoic Inc"
    
    ElseIf (cboparish.Text = "Select Parish") Then
        MsgBox "Please select a parish", vbExclamation + vbOKOnly, "Error"
    ElseIf (txtstreet = "") Then
    
        MsgBox "Street should contain a street address", vbExclamation + vbOKOnly, "Atmoic Inc"
    ElseIf (txtphoneno.Text = "") And (txtcellno.Text = "") Then
        MsgBox "Work and Cell number is compulsory", vbInformation + vbOKOnly, "Atomic Inc"
    
    ElseIf (optict.Value = False) And (optassessmentprogramme.Value = False) And (optdbt.Value = False) And (opttvet.Value = False) And (optcarrerdev.Value = False) And (optictinstruc.Value = False) And (opteventsmanagement.Value = False) And (opteduandtranng.Value = False) And (optcnstrudsitemanagement.Value = False) Then
        MsgBox "Please select your respective department", vbQuestion + vbOKOnly, "Atomic Inc"
Else
     If (optftime.Value = True) Then
            Adoaddlec.Recordset.Fields("status") = "ft"
        ElseIf (optptime.Value = True) Then
            Adoaddlec.Recordset.Fields("status") = "pt"
       End If
       If (cboparish.Text = "Clarendon") Then
            Adoaddlec.Recordset.Fields("parish") = 1
       
        ElseIf (cboparish.Text = "Hanover") Then
            Adoaddlec.Recordset.Fields("parish") = 2
       
        ElseIf (cboparish.Text = "Manchester") Then
            Adoaddlec.Recordset.Fields("parish") = 3
       
        ElseIf (cboparish.Text = "Portland") Then
            Adoaddlec.Recordset.Fields("parish") = 4
       
        ElseIf (cboparish.Text = "St.Andrew") Then
            Adoaddlec.Recordset.Fields("parish") = 5
       
        ElseIf (cboparish.Text = "St.Ann") Then
            Adoaddlec.Recordset.Fields("parish") = 6
       
        ElseIf (cboparish.Text = "St.Catherine") Then
            Adoaddlec.Recordset.Fields("parish") = 7
       
        ElseIf (cboparish.Text = "St.Elizabeth") Then
            Adoaddlec.Recordset.Fields("parish") = 8
       
        ElseIf (cboparish.Text = "St.James") Then
            Adoaddlec.Recordset.Fields("parish") = 9
       
        ElseIf (cboparish.Text = "St.Mary") Then
            Adoaddlec.Recordset.Fields("parish") = 10
       
        ElseIf (cboparish.Text = "St.Thomas") Then
            Adoaddlec.Recordset.Fields("parish") = 11
       
        ElseIf (cboparish.Text = "Trelwany") Then
            Adoaddlec.Recordset.Fields("parish") = 12
       
        ElseIf (cboparish.Text = "Westmoreland") Then
            Adoaddlec.Recordset.Fields("parish") = 13
        End If
        If (optict.Value = True) Then
                Adoaddlec.Recordset.Fields("department") = 1
                
        ElseIf (optassessmentprogramme.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 2
        ElseIf (optdbt.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 3
        ElseIf (opttvet.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 4
        ElseIf (optcarrerdev.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 5
        ElseIf (optictinstruc.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 6
        ElseIf (opteventsmanagement.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 7
        ElseIf (opteduandtranng.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 8
        ElseIf (optcnstrudsitemanagement.Value = True) Then
            Adoaddlec.Recordset.Fields("department") = 9
        End If
    Adoaddlec.Recordset.Update
    MsgBox "Record Updates", , "Atomic Inc"
End If
End Sub

Private Sub Form_Load()
Call status
Call department
Call parish
End Sub
Private Sub status()
Dim stat_us As String
stat_us = Trim(Adoaddlec.Recordset.Fields("status"))
    If (stat_us = "ft") Then
        optftime.Value = True
    ElseIf (stat_us = "pt") Then
        optptime.Value = True
    End If
End Sub

Private Sub department()
Dim dep As String
dep = Trim(Adoaddlec.Recordset.Fields("department"))
    If (dep = 1) Then
        optict.Value = True
        ElseIf (dep = 2) Then
            optassessmentprogramme.Value = True
        ElseIf (dep = 3) Then
            optdbt.Value = True
        ElseIf (dep = 4) Then
            opttvet.Value = True
        ElseIf (dep = 5) Then
            optcarrerdev.Value = True
        ElseIf (dep = 6) Then
        optictinstruc.Value = True
        ElseIf (dep = 7) Then
            opteventsmanagement.Value = True
        ElseIf (dep = 8) Then
            opteduandtranng.Value = True
        ElseIf (dep = 9) Then
            optcnstrudsitemanagement.Value = True
    End If
End Sub


Private Sub parish()
Dim par As String
par = Trim(Adoaddlec.Recordset.Fields("parish"))
If (par = 1) Then
    cboparish.Text = "Clarendon"
ElseIf (par = 2) Then
    cboparish.Text = "Hanover"
ElseIf (par = 3) Then
    cboparish.Text = "Manchester"
ElseIf (par = 4) Then
    cboparish.Text = "Portland"
ElseIf (par = 5) Then
    cboparish.Text = "St.Andrew"
ElseIf (par = 6) Then
    cboparish.Text = "St.Ann"
ElseIf (par = 7) Then
    cboparish.Text = "St.Catherine"
ElseIf (par = 8) Then
    cboparish.Text = "St.Elizabeth"
ElseIf (par = 9) Then
    cboparish.Text = "St.James"
ElseIf (par = 10) Then
    cboparish.Text = "St.Mary"
ElseIf (par = 11) Then
    cboparish.Text = "St.Thomas"
ElseIf (par = 12) Then
    cboparish.Text = "Trelwany"
ElseIf (par = 13) Then
    cboparish.Text = "Westmoreland"
End If
End Sub
' checking if the first name has numbers in it and converting possible numeric values to characters/string
Private Sub txtfname_LostFocus()
Dim fname As String
fname = CStr(txtfname.Text)
If IsNumeric(fname) = True Then
    MsgBox "First name should not contain numbers only", vbInformation + vbOKOnly, "Atomic Inc"
    txtfname.Text = Empty
    txtfname.SetFocus
End If
End Sub
' checking if the last name has numbers in it and converting possible numeric values to characters/string
Private Sub txtlname_LostFocus()
Dim lname As String
lname = CStr(txtlname.Text)
If IsNumeric(lname) = True Then
    MsgBox "Last name should not be numbers only", vbInformation + vbOKOnly, "Atomic Inc"
    txtlname.Text = Empty
    txtlname.SetFocus
End If
End Sub
' checking if the middle name has numbers in it and converting possible numeric values to characters/string
Private Sub txtmname_LostFocus()
Dim mname  As String
mname = CStr(txtmname.Text)
If IsNumeric(mname) = True Then
    MsgBox "Middle name should not contain numbers only", vbInformation + vbOKOnly, "Atomic Inc"
    txtmname.Text = Empty
    txtmname.SetFocus
End If
End Sub
' checking if the street has only numbers in it and converting posible numeric values to characters/string
Private Sub txtstreet_LostFocus()
Dim street As String

street = CStr(txtstreet.Text)
If IsNumeric(street) = True Then
    MsgBox "Please ensure that this field doesn't contain only numeric values"
    txtstreet = Empty
    txtstreet.SetFocus
End If
End Sub

so thanks fo r all the help so far i however got closer to my goal i dodn't close my elseif the right place i have another problem with my parish info not saving in my databaseplease let me know if u see any error in my above nn current code on my save button well partially any ways

88omar, have you ever heard of arrays?

I'm looking briefly at what your doing and the code looks extremely long and unneccesary. Why not create an array of the name 'Parish' for example then store all your values into that, and have things reference it.

yes i've hear of it but i don't know how to do it in vb

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.