Wierd text box problem

poporacer

Registered User.
Local time
Today, 10:31
Joined
Aug 30, 2007
Messages
136
I have on problem and one curiosity.
The first problem I have is that I have 2 listboxes, sort of like cascading listboxes. You select a record in the first listbox and the second listbox is generated from the criteria in the first listbox. The problem I have is that when you add a new incident #(from clicking on the button below) the incident gets added properly but if you select the incident and inmate that was just added, the text boxes get populated from the first record in the table not from the recordset...the text boxes should be blank until you add the data.....

The curiosity is that I saw in some code somewhere a neat way to populate unbound controls in a form. On this form, if the controls are bound, when the form opens, the controls are populated with the first record when I want them to be blank. (see frmEdit). The code I saw was something like this...

for x=1 to Controls.count
if control.type=label then next (this is to skip labels or other controls you want to skip)
control(x).text = ""
next

You could also use this to store the data in to a record

for x=1 to Controls.count
if control.type=label then next (this is to skip labels or other controls you want to skip)
rs.fields(x)=control(x).text
next

I know I am probably way off in the syntax but at least it gives you a clue of what I would like to do...would cut down on a lot of code.

But then again, if I can get the text boxes to be blank when the form opens, I wouldn't have to go through all this

Thanks!
 

Attachments

Last edited:
What you are looking for is TypeOf.

EG.

Code:
Public Sub check_type()
Dim vItem As Variant

    For Each vItem In Me.Controls
        If TypeOf vItem Is TextBox Then
            vItem.Value = "finish"
        End If
    Next vItem
    
End Sub

Use TypeOf to check for the specific 'TypeOf' control you want then have your way with it.:D
 
Thanks...I will try this. I want to incorporate saving fields as well so I am going to try this
Public Sub check_type()
Dim vItem As Variant
Dim iCount as integer

iCount=1
For Each vItem In Me.Controls
If TypeOf vItem Is TextBox Then
rs.fields(icount)=me.controls.text
End If
iCount=iCount+1
Next vItem

End Sub

I know I have to declare the rs and db.. I will try this and see how it works.

Any suggestions on the problem with the data showing in the text boxes?
 
??? I tried this and I got a Next without for error.. I am not sure why. Here is the code:
Private Sub lstLogNum_AfterUpdate()
Dim vItem As Variant
DoCmd.GoToRecord , , acNewRec

For Each vItem In Me.Controls
If TypeOf vItem Is TextBox Then
vItem.Value = ""
End If
If TypeOf vItem Is CheckBox Then
vItem.Value = ""
Next vItem

End Sub
 
Code:
Private Sub lstLogNum_AfterUpdate()
Dim vItem As Variant

    DoCmd.GoToRecord , , acNewRec

    For Each vItem In Me.Controls
        If TypeOf vItem Is TextBox Then
            vItem.Value = ""
        End If
        If TypeOf vItem Is CheckBox Then
            vItem.Value = ""
        [b][COLOR="Red"]End If[/COLOR][/b]
    Next vItem

End Sub
 

Users who are viewing this thread

Back
Top Bottom