Not really. The best way is to let Access do the work If you don't want to use a bound form, then you have to do the work Access does for you. You should also check for Null, and probably spaces in an empty string. How do you guard against a record being written every time somebody uses the form and the criteri are met?
brownti via AccessMonster.com wrote:
[Quoted Text] > 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
|