change data using public sub

srferson

New member
Local time
Today, 06:49
Joined
Feb 22, 2010
Messages
4
Behind a form I have the same code over and over for a bunch of checkboxes:

If chkBlue = -1 Then
Blue = 1
Red = 0
End If

If chkBlue is the checkbox on the form for the field Blue in my table and there is also another field named Red in my table, when Blue's checkbox is checked, Blue is set to 1 and Red is set to 0.

That works. But how do I turn this into a Public Sub in a module?

This doesn't work:

Public Sub CheckUncheck(Chk1 As Control, CheckVar As String, UncheckVar As String)
If Chk1 = -1 Then
CheckVar = 1
UncheckVar = 0
End If
End Sub

Call CheckUncheck(chkBlue, Blue, Red)


I'm sure I'm oversimplifying it, but my Friday brain is not helping me. I can't figure out how to write it so it works.
 
Hi;

Code:
Public Function CheckUncheck(Chk1 As Control, CheckVar As Control, UncheckVar As Control)
If Chk1 = -1 Then
CheckVar = 1
UncheckVar = 0
End If
End Function
 
Hi;

Code:
Public Function CheckUncheck(Chk1 As Control, CheckVar As Control, UncheckVar As Control)
If Chk1 = -1 Then
CheckVar = 1
UncheckVar = 0
End If
End Function

Thanks for the fast response!
Unfortunately, this doesn't work. It's actually the way I tried it at first too. But I just tried it again and I call it like this:

Call CheckUncheck(chkBlue, Blue, Red)

And I get a type mismatch.
Keep in mind that Blue and Red are fields in the table the form is based on, but I don't actually have controls called Blue and Red on the form. I think that may be part of my issue?
 
Hi again ;)

Call CheckUncheck(chkBlue, FormControl_Blue_Name, FormControl_Red_Name)

same as chkblue
 
Hi again ;)

Call CheckUncheck(chkBlue, FormControl_Blue_Name, FormControl_Red_Name)

same as chkblue


If I am understanding you correctly, you're saying that the control names need to go there. But there are no control names. Blue and Red do not have controls on the form. They are fields in the underlying table. I realize I could put controls on the form for Blue and Red, but I'd prefer not to if there is another proper way to do this since this would be the only reason to create those controls.
 
Sorry my poor English, but i dont understand.

Your first mesasage, you said..

If chkBlue = -1 Then
Blue = 1
Red = 0
End If

What is blue and red? How do you set your table fields?
 
*sigh* I think I was being an idiot. Well, not an idiot, but I was looking at something in the wrong way.

I'd explain, but it's too confusing to explain my brain. Especially my Friday brain.

Thank you for your help. You helped my brain wake up and kick itself.

:rolleyes:
 

Users who are viewing this thread

Back
Top Bottom