B
Billy B
I have a form with three unbound controls: two combobox and one listbox. The
values for the controls come from the following code:
Private Sub Form_Load()
Dim cboPlantType As ComboBox
Set cboPlantType = Me!cboPlantType
With cboPlantType
.RowSourceType = "Value List"
.RowSource = "Annual;Perennial;Tropical"
End With
Me!cboPlantType = Me!cboPlantType.ItemData(0)
Dim cboPlantCat As ComboBox
Set cboPlantCat = Me!cboPlantCat
With cboPlantCat
.RowSourceType = "Value List"
.RowSource = "Aquatic;Bush;Plant;Shrub;Tree;Vine"
End With
Me!cboPlantCat = Me!cboPlantCat.ItemData(0)
Dim cboPlantLoc As ComboBox
Set cboPlantLoc = Me!lstLoc
With lstLoc
.RowSourceType = "Value List"
.RowSource = "Full Sun;Full Sun / Partial shade;Shade / Partial
sun;Shade"
End With
Me!lstLoc = Me!lstLoc.ItemData(0)
End Sub
The following code is supposed to insert the values from the form to the
table. It all works OK except the values for the unbound controls. The form
values show in the variables when I step through the code and also in the sql
statement. Problem is that the unbound values are not inserted into the
table. All table fields are text. I have triple checked the table field names
for accuracy and they are a match.
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
On Error Resume Next
Dim strInsertIt As String
Dim strsqlDel as string
Dim strPlantName As String, strAlias As String, strBotonName As String,
strPlantType As String
Dim strPlantCat As String, strGrowthSize As String, strPlantingLoc As
String, strDesc As String
Dim strCulture As String, strMoisture As String, strHardiness As String,
strFeatures As String
Dim strUsage As String, strWarn As String
Dim objPic As Object
intNextNum = DMax("PlantID", "tblPlants")
intNextNum = intNextNum + 1
strPlantName = Me.PlantName.Value
strAlias = Me.Alias.Value
strBotonName = Me.BotonName.Value
strPlantType = Me.cboPlantType.Value
strPlantCat = Me.cboPlantCat.Value
strGrowthSize = Me.GrowthSize.Value
strplantloc = Me.lstLoc.Value
strDesc = Me.Description.Value
strCulture = Me.Culture.Value
strMoisture = Me.Moisture.Value
strHardiness = Me.HardinessZones.Value
strFeatures = Me.Features.Value
strUsage = Me.Usage.Value
strWarn = Me.PlantWarnings.Value
'objPic = Me.Pic
If Me.PlantName.Value = "" Then
DoCmd.SetWarnings False
strsqlDel = "Delete * from tblPlants WHERE Plantname = '" & "'"
DoCmd.RunSQL strsqlDel
DoCmd.SetWarnings True
DoCmd.Closeform acForm, ("frmPlantsAdd")
Else
strInsertIt = "INSERT INTO tblPlants
(PlantID,PlantName,Alias,Botoname,PlantType,PlantCat,GrowthSize,PlantingLoc,Description,)" & _
"Culture,Moisture,HardinessZones,Features,Usage,PlantWarnings,Pic)" & _
"VALUES (""" & intNextNum & """,""" & strPlantName & """, """ &
strAlias & """, """ & strBotonName & """, """ & strPlantType & """ & " & _
" """ & strPlantCat & """,""" & strGrowthSize & """, """ &
strplantloc & """, """ & strDesc & """, " & _
" """ & strCulture & """,""" & strMoisture & """,""" &
strHardiness & """, """ & strFeatures & """, " & _
" """ & strUsage & """, """ & strWarn & """);"
DoCmd.RunSQL strInsertIt
End If
'Delete Plantname rows where contains invalid data in PlantName
DelInvalidRows
DoCmd.Close acForm, ("frmPlantsAdd")
Exit_cmdClose_Click:
'procedure here
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
Thank you.
values for the controls come from the following code:
Private Sub Form_Load()
Dim cboPlantType As ComboBox
Set cboPlantType = Me!cboPlantType
With cboPlantType
.RowSourceType = "Value List"
.RowSource = "Annual;Perennial;Tropical"
End With
Me!cboPlantType = Me!cboPlantType.ItemData(0)
Dim cboPlantCat As ComboBox
Set cboPlantCat = Me!cboPlantCat
With cboPlantCat
.RowSourceType = "Value List"
.RowSource = "Aquatic;Bush;Plant;Shrub;Tree;Vine"
End With
Me!cboPlantCat = Me!cboPlantCat.ItemData(0)
Dim cboPlantLoc As ComboBox
Set cboPlantLoc = Me!lstLoc
With lstLoc
.RowSourceType = "Value List"
.RowSource = "Full Sun;Full Sun / Partial shade;Shade / Partial
sun;Shade"
End With
Me!lstLoc = Me!lstLoc.ItemData(0)
End Sub
The following code is supposed to insert the values from the form to the
table. It all works OK except the values for the unbound controls. The form
values show in the variables when I step through the code and also in the sql
statement. Problem is that the unbound values are not inserted into the
table. All table fields are text. I have triple checked the table field names
for accuracy and they are a match.
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
On Error Resume Next
Dim strInsertIt As String
Dim strsqlDel as string
Dim strPlantName As String, strAlias As String, strBotonName As String,
strPlantType As String
Dim strPlantCat As String, strGrowthSize As String, strPlantingLoc As
String, strDesc As String
Dim strCulture As String, strMoisture As String, strHardiness As String,
strFeatures As String
Dim strUsage As String, strWarn As String
Dim objPic As Object
intNextNum = DMax("PlantID", "tblPlants")
intNextNum = intNextNum + 1
strPlantName = Me.PlantName.Value
strAlias = Me.Alias.Value
strBotonName = Me.BotonName.Value
strPlantType = Me.cboPlantType.Value
strPlantCat = Me.cboPlantCat.Value
strGrowthSize = Me.GrowthSize.Value
strplantloc = Me.lstLoc.Value
strDesc = Me.Description.Value
strCulture = Me.Culture.Value
strMoisture = Me.Moisture.Value
strHardiness = Me.HardinessZones.Value
strFeatures = Me.Features.Value
strUsage = Me.Usage.Value
strWarn = Me.PlantWarnings.Value
'objPic = Me.Pic
If Me.PlantName.Value = "" Then
DoCmd.SetWarnings False
strsqlDel = "Delete * from tblPlants WHERE Plantname = '" & "'"
DoCmd.RunSQL strsqlDel
DoCmd.SetWarnings True
DoCmd.Closeform acForm, ("frmPlantsAdd")
Else
strInsertIt = "INSERT INTO tblPlants
(PlantID,PlantName,Alias,Botoname,PlantType,PlantCat,GrowthSize,PlantingLoc,Description,)" & _
"Culture,Moisture,HardinessZones,Features,Usage,PlantWarnings,Pic)" & _
"VALUES (""" & intNextNum & """,""" & strPlantName & """, """ &
strAlias & """, """ & strBotonName & """, """ & strPlantType & """ & " & _
" """ & strPlantCat & """,""" & strGrowthSize & """, """ &
strplantloc & """, """ & strDesc & """, " & _
" """ & strCulture & """,""" & strMoisture & """,""" &
strHardiness & """, """ & strFeatures & """, " & _
" """ & strUsage & """, """ & strWarn & """);"
DoCmd.RunSQL strInsertIt
End If
'Delete Plantname rows where contains invalid data in PlantName
DelInvalidRows
DoCmd.Close acForm, ("frmPlantsAdd")
Exit_cmdClose_Click:
'procedure here
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
Thank you.