Using .controlsource to update an unbound textbox's control

Nangasaur

Registered User.
Local time
Today, 12:57
Joined
May 9, 2010
Messages
29
Access 2007
Windows 7

So I'm somewhat back to my original problem I posted about several weeks ago, where I am attempting to set the control source of a text box based on very simple criteria: Is a field from a set of fields in my table null? If yes, set the control source to that field name. If it's not null, check the next field in the sequence to see if it is null.

Here's the code I'm working with currently, that is giving me quite a headache:

Code:
Private Sub Form_Current()
Dim I As Long
For I = 1 To 32
    If ("DC" & I) = Null Then
    
       Me!New_Date_Completedtxtbox.ControlSource = ("DC" & I)
       
       If I > 1 Then
       
        Me!Old_Date_Completedtxtbox.ControlSource = ("DC" & I - 1)
    
          Exit Sub
        
       End If
       
    End If
    
Next I

End Sub

What's supposed to happen is the user selects a record with a combo box bound to a query. Upon selecting that record, the above code is supposed to set the control source of two different text boxes. One text box is supposed to be set to the first field found empty, and the second text box is supposed to be set to the field BEFORE the one found empty.

And feh...it's not working, and giving me quite a headache. I've tried firing this code from several different events, to no avail.

Any advice would be wonderful. Thank you.
 
The statement

Code:
"DC" & I

Will never be equal to null.. it will always be DC1.. DC2.. DC3 and so on all the way to DC32
 
Those are the names of the fields from my table, which I need to check if those fields are null.

Like I said, any advice on how to make my code work would be helpful. Thanks.
 
Oh, if those fields are linked in your form, you might want to try this instead

Code:
if me!DC = Null then
 
Oh, if those fields are linked in your form, you might want to try this instead

Code:
if me!DC = Null then
Well, I have tried

Code:
If Me("DC" & I) = Null Then
Which didn't work, sadly.

The form's recordsource is a query, which of course has every instance of the fields DC1 thru DC32. A combo box selects the current record from the record source. After selecting the record I want, I need the controls' controlsource set according to the above criteria.
 
Bah, I got it :)

Changed
Code:
If Me("DC" & I) = Null Then
To
Code:
If IsNull(Me("DC" & I)) Then

I'm baffled as to why this works, but the other way did not.
 

Users who are viewing this thread

Back
Top Bottom