Hi, I have three sql statements that run when the user clicks "Done Adding" button when adding a new "Case" to the database.
Sql should be putting the new "Case Name" and ID in three different tables (these tables are also linked to other databases)
the 1st, and 3rd sql statement work fine, but the second does not. No user side errors, no VB compile errors, just simply does not insert the information into the table "tblEligibility"
there is one difference with this eligibility table- the "FamilyID" does not have a space like the other tables do. There are many forms based on this table, and many errors occur if I change the table id to include the space.
any ideas?? what cant I do to get this info inserted into tblEligibility? The FamilyID not having a space should not matter, right?
Sql should be putting the new "Case Name" and ID in three different tables (these tables are also linked to other databases)
the 1st, and 3rd sql statement work fine, but the second does not. No user side errors, no VB compile errors, just simply does not insert the information into the table "tblEligibility"
there is one difference with this eligibility table- the "FamilyID" does not have a space like the other tables do. There are many forms based on this table, and many errors occur if I change the table id to include the space.
any ideas?? what cant I do to get this info inserted into tblEligibility? The FamilyID not having a space should not matter, right?
Code:
Private Sub cmdDoneAdding_Click()
Dim MySql As String
Dim MySqlTwo As String
Dim MySqlThree As String
Dim NewFamId As String
Dim Newchildid As String
Dim LastIdFam As Long
Dim LastIdChild As Long
Dim LastNameValue As String
Dim FirstNameValue As String
Dim NewCaseName As String
If Not Me.Case_Name = "" Then
Me.IntakeDate = Now()
NewCaseName = Me.Case_Name
LastNameValue = "(Enter Last Name)"
FirstNameValue = "(Enter First Name)"
LastIdFam = CurrentDb.OpenRecordset("SELECT Max([Family ID]) FROM tblFamilyData;")(0)
LastIdChild = CurrentDb.OpenRecordset("SELECT Max([Child ID]) FROM tblChildData;")(0)
'MsgBox " Max ids: " & LastIdFam & " : " & LastIdChild
NewFamId = LastIdFam + 1
Newchildid = LastIdChild + 1
'MsgBox " New ids: " & Newfamid & " : " & Newchildid
txtFamilyId.Value = NewFamId
MySql = "INSERT INTO tblChildData " & _
"( [Family ID], [Child ID], [Case Name], [First Name], [Last Name])" & _
" VALUES ('" & NewFamId & "','" & Newchildid & "','" & NewCaseName & "', '" & FirstNameValue & "', '" & LastNameValue & "');"
MySqlTwo = "INSERT INTO tblEligibility " & _
"( [FamilyID], [Case Name])" & _
" VALUES ('" & NewFamId & "','" & NewCaseName & "');"
MySqlThree = "INSERT INTO tblRiskAssessment " & _
"( [Family ID], [Case Name])" & _
" VALUES ('" & NewFamId & "','" & NewCaseName & "');"
x = MsgBox("Are you sure you want to add " & "'" & NewCaseName & "'" & " as a New Case?", vbInformation + vbYesNo, "Childrens Crisis Center")
If x = vbNo Then
MsgBox NewCaseName & " was NOT added!", vbExclamation, "Childrens Crisis Center"
Me.Undo
Exit Sub
Else
DoCmd.SetWarnings False
DoCmd.RunSQL MySql
DoCmd.RunSQL MySqlTwo
DoCmd.RunSQL MySqlThree
DoCmd.SetWarnings True
DoCmd.Close
DoCmd.OpenForm "frmFamilyData", acNormal, NewCaseName
End If
Else
MsgBox "You have not entered a new Case Name yet!", vbExclamation
Exit Sub
End If
End Sub