Home > Archive > MS Access database support > February 2006 > What's wrong with my code?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author What's wrong with my code?
Keith Wilby

2006-02-20, 9:24 am

This code fails at the very last line and it's driving me nuts! Can anyone
see why? It's called from a command button on a form and the query returns
one record:

Call libRecalcHours(Me, "txtNotApproved", "Select * from
qryHoursNotApproved")


Public Sub libRecalcHours(frm As Form, strCtlName As String, strSQL As
String)

Dim db As DAO.Database, rs As DAO.Recordset, strSum As String
Set db = CurrentDb

Set rs = db. OpenRecordset(strSQL
)
With rs
.MoveLast
strSum = !SumHours
End With
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

frm.strCtlName.Value = strSum ** Here is where it fails
("Application-defined or object-defined error"). "txtNotApproved" is
unbound.

End Sub


Many thanks.
Keith.


Keith Wilby

2006-02-20, 9:24 am

"Keith Wilby" <here@there.com> wrote in message
news:43f9cb83$1_1@gl
kas0286.greenlnk.net...
> This code fails at the very last line and it's driving me nuts! Can
> anyone see why? It's called from a command button on a form and the query
> returns one record:
>


Argh! Doesn't matter - I should be passing the actual control, not it's
name!


RoyVidar

2006-02-20, 9:24 am

Keith Wilby wrote in message < 43f9cb83$1_1@glkas02
86.greenlnk.net> :
> This code fails at the very last line and it's driving me nuts! Can anyone
> see why? It's called from a command button on a form and the query returns
> one record:
>
> Call libRecalcHours(Me, "txtNotApproved", "Select * from
> qryHoursNotApproved")
>
>
> Public Sub libRecalcHours(frm As Form, strCtlName As String, strSQL As
> String)
>
> Dim db As DAO.Database, rs As DAO.Recordset, strSum As String
> Set db = CurrentDb
>
> Set rs = db. OpenRecordset(strSQL
)
> With rs
> .MoveLast
> strSum = !SumHours
> End With
> rs.Close
> Set rs = Nothing
> db.Close
> Set db = Nothing
>
> frm.strCtlName.Value = strSum ** Here is where it fails ("Application-defined
> or object-defined error"). "txtNotApproved" is unbound.
>
> End Sub
>
>
> Many thanks.
> Keith.


You've passed the control name as string, then you probably need
something more like this

frm. controls(strCtlName)
.Value = strSum

One question - the sum, is that a text? If not, perhaps consider
declaring the strSum variable as some numeric datatype?

BTW - I don't think there's any need to close the db object variable,
as
you haven't opened it - releasing should be enough.

--
Roy-Vidar


Keith Wilby

2006-02-20, 9:24 am

"RoyVidar" < roy_vidarNOSPAM@yaho
o.no> wrote in message
news:mn.a3967d62b48e10be.33955@yahoo.no...
>
> You've passed the control name as string, then you probably need
> something more like this
>
> frm. controls(strCtlName)
.Value = strSum
>
> One question - the sum, is that a text? If not, perhaps consider
> declaring the strSum variable as some numeric datatype?
>
> BTW - I don't think there's any need to close the db object variable, as
> you haven't opened it - releasing should be enough.
>


Thanks Roy, I'm having a bad day!

Keith.


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com