|
-
Mar 18th, 2005, 03:20 PM
#1
Thread Starter
Frenzied Member
Loop thru controls in form - what's wrong?
This is an Access 97 db. I want to loop through the controls in the detail section of a form only, and have the code below. Access throws an Application or Object defined error at the indicated spot. If I highlight "ctl", Access gives the value that's in the textbox which is the first control, e.g. the date. I'm basically trying to make sure the user has entered at least some data in the detail area of the form before it's saved. Thanks.
VB Code:
Private Function CheckForData() As Boolean
Dim ctl As Control
Dim i As Integer
For Each ctl In Me.Controls <--- highlighting ctl = value in that control
[COLOR=Red][B]i = Forms![Survey Review].ctl.Section [/B] [/COLOR] <--- error here
If i = acDetail Then
If TypeOf ctl Is CheckBox Then
If ctl.Value = True Then
CheckForData = True
Exit Function
End If
ElseIf TypeOf ctl Is TextBox Then
If Len(ctl.Text) > 0 Then
CheckForData = True
Exit Function
End If
End If
End If
Next
End Function
Tengo mas preguntas que contestas
-
Mar 19th, 2005, 05:51 PM
#2
Junior Member
Re: Loop thru controls in form - what's wrong?
A control does not have a section property.
Your function does not give you
user has entered at least some data in the detail area of the form before it's saved
Your function misses bound combo box value.
If Me.Dirty = True then - data has changed in a form.
VBA uses acCheckBox and acTextBox, not CheckBox nd TextBox.
-
Mar 21st, 2005, 11:12 AM
#3
Thread Starter
Frenzied Member
Re: Loop thru controls in form - what's wrong?
Ok, I'll try that, thanks. Help for Section Property contains this, though:
You can use the Section property to identify a section of a form or report and provide access to the properties
of that section. You can also identify controls by the section of a form or report where the control appears....
For controls, you can use the Section property to determine which section of a form or report a control is in.
The following example uses the Section
property to determine which section contains the CustomerID control.
Dim intSectionNumber As Integer
intSectionNumber = Forms!Customers!CustomerID.Section
And I still don't know why ctl is picking up the value in the control, rather than the control itself.
Me.Dirty doesn't do quite what I want. Initial data is entered on a different form, and this form is used for reviewing a/o editing. But it's possible that the user will make no changes, so the Dirty property never gets set. That's why I want to iterate through the controls in the Detail section (the page header section other data - name, department, etc, that the user doesn't normally enter or edit). No particular control has to have data, but there has to be some data before they save it.
Last edited by salvelinus; Mar 21st, 2005 at 11:23 AM.
Tengo mas preguntas que contestas
-
Mar 22nd, 2005, 09:59 AM
#4
Re: Loop thru controls in form - what's wrong?
me.controls - all controls on form.
I;m not sure here but I think the sections come before the controls, so you are looking at only one section. ie
me.sections(0).controls(<loopnum>)
Its been a while since I bothered having sections on forms... so this may be wrong
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|