By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,959 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,959 IT Pros & Developers. It's quick & easy.

What's wrong with my code?

P: n/a
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.
Feb 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Keith Wilby" <he**@there.com> wrote in message
news:43**********@glkas0286.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!
Feb 20 '06 #2

P: n/a
Keith Wilby wrote in message <43**********@glkas0286.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
Feb 20 '06 #3

P: n/a
"RoyVidar" <ro*************@yahoo.no> wrote in message
news:mn***********************@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.
Feb 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.