B
brownti via AccessMonster.com
I have a form with unbound controls that i need to use to create records in a
single table. I have figured out a way to do this (see code below), but dont
think that it is the best way. Can anyone help me clean up the code below?
I will have about 6 more controls to add to it once i am done. Thanks.
Dim strSQL As String
Dim strUnitID As String
strUnitID = Me.UnitID
If Me.txtMillworkDelivery <> "" Then
strSQL = "INSERT INTO tblNewDelivery ( UnitID, DeliveryDescription,
DeliveryDate )" & _
"SELECT tblUnitSelections.UnitID, 'MillworkDelivery' AS DeliveryDescription,
'" & _
Me.txtMillworkDelivery & "' AS DeliveryDate FROM tblUnitSelections WHERE ((
(tblUnitSelections.UnitID)=" & strUnitID & "));"
DoCmd.RunSQL (strSQL)
strSQL = ""
End If
If Me.txtCabinetDelivery <> "" Then
strSQL = "INSERT INTO tblNewDelivery ( UnitID, DeliveryDescription,
DeliveryDate )" & _
"SELECT tblUnitSelections.UnitID, 'CabinetDelivery' AS DeliveryDescription,
'" & _
Me.txtCabinetDelivery & "' AS DeliveryDate FROM tblUnitSelections WHERE ((
(tblUnitSelections.UnitID)=" & strUnitID & "));"
DoCmd.RunSQL (strSQL)
strSQL = ""
End If
single table. I have figured out a way to do this (see code below), but dont
think that it is the best way. Can anyone help me clean up the code below?
I will have about 6 more controls to add to it once i am done. Thanks.
Dim strSQL As String
Dim strUnitID As String
strUnitID = Me.UnitID
If Me.txtMillworkDelivery <> "" Then
strSQL = "INSERT INTO tblNewDelivery ( UnitID, DeliveryDescription,
DeliveryDate )" & _
"SELECT tblUnitSelections.UnitID, 'MillworkDelivery' AS DeliveryDescription,
'" & _
Me.txtMillworkDelivery & "' AS DeliveryDate FROM tblUnitSelections WHERE ((
(tblUnitSelections.UnitID)=" & strUnitID & "));"
DoCmd.RunSQL (strSQL)
strSQL = ""
End If
If Me.txtCabinetDelivery <> "" Then
strSQL = "INSERT INTO tblNewDelivery ( UnitID, DeliveryDescription,
DeliveryDate )" & _
"SELECT tblUnitSelections.UnitID, 'CabinetDelivery' AS DeliveryDescription,
'" & _
Me.txtCabinetDelivery & "' AS DeliveryDate FROM tblUnitSelections WHERE ((
(tblUnitSelections.UnitID)=" & strUnitID & "));"
DoCmd.RunSQL (strSQL)
strSQL = ""
End If