Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Unbound controls to create records

Geek News

Unbound controls to create records
"brownti via AccessMonster.com" <u31540[ at ]uwe> 12/26/2008 5:18:59 PM
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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1

Re: Unbound controls to create records
"Mike Painter" <mddotpainter[ at ]sbcglobal.net> 12/26/2008 9:59:46 PM
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


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net