Update table from code using recordset object

  • Thread starter Thread starter Greg Green
  • Start date Start date
G

Greg Green

Hello

I have several objectives and need advice on them:

1) Use a recordset object in code from an unbound form to select from a
table into each of about a hundred text boxes on the form. *I have this
working well* by cycling through a function (below) once for each text box.

2) If a user changes the value in a text box, I want to UPDATE that value in
the table by calling a function that "rewrites" the value in the table. From
what I know, the "form.dirty" property is not usable in this situation as
the form is unbound.

3) If a user wants to author the value in a text box for the first time
(value is not yet in database) I'd like to INSERT a record.

Thanks in advance!

----------------------------------------------------------------

I call the function below with this code:

modData.PopulateDoubleCell Me, "H28", "5005", "11/21/2003"
----------------------------------------------------------------
I use the function below to select a value into a recordset object and
deposit it into each text box. I'm trying to use something like it to author
back to the table as well as update the table if a value has changed.

Public Function PopulateDoubleCell(frmReferrer As Form, sCellXY As String,
sPoint As Long, sDate As Date)
On Error Resume Next

strSQL = "SELECT DailyOps_Values.Value FROM DailyOps_Values
WHERE(((DailyOps_Values.Date)=#" & sDate & "#)
AND((DailyOps_Values.PointID)= " & sPoint & "));"

rst.Open strSQL, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

Set frm = frmReferrer
With frm
Set ctl = frm.Controls(sCellXY)

ControlValue = Nz(rst("Value"), 0)
ctl.Value = ControlValue

End With

'Clost out the recordset and reset variables so they can be reused in other
procedures
rst.Close
Set rst = Nothing
lngPointID = Null
strCellID = Null
ControlValue = 0
strSQL = ""

End Function
 
Anybody else smell homework? :-D

It's going to require code in either the Before or After Update procedure of
every field. If it is updated, then execute the UPDATE query.

For the APPEND, when the Key field is entered, if it doesn't exist in the
table, then run the APPEND to add the record.

If this is really not a homework assignment, you may want to post how it is
that you've gotten into this situation, because it appears to be a pretty
bad one. For starters, any form with 100+ textboxes most likely has an
incredibly bad data model behind it.

--
HTH,

Steve Clark, Access MVP
FMS, Inc.
Professional Solutions Group
http://www.FMSInc.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Is your Access database too slow?
Are you ready to upgrade to SQL Server?
Contact us for optimization and/or upsizing!
http://www.FMSInc.com/consulting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
Back
Top