Unbound controls to create records

  • Thread starter brownti via AccessMonster.com
  • Start date
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
 
M

Mike Painter

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top