Textbox value dependant on an if statement

hijacked101

New member
Local time
Today, 19:16
Joined
Sep 4, 2008
Messages
7
I am creating a database and i would like to assign a piece of code to a command button, so that when it is pressed it generated an automated value for a text box based on tick boxes on the forum.

I attempted to do something like the following:

Private Sub Command130_Click()
if me.tickbox1.value = 0 then
me.textbox1.value = "tickbox one was left blank. "
End If
If me.tickbox2.valuse = 0 then
me.tectbox1.value = "tickbox two was left blank. "
end if.
End sub

upon clicking the command button when both tickboxes are unticked i get the following:

"tickbox two was left blank"

My desired results for when both tick boxes are left unticked is the following:

"tickbox one was left blank. tickbox two was left blank"

I am now trying to get my results by doing something like the following:

me.textbox.value = ((if me.tickbox1.value = 0 then
me.textbox1.value = "tickbox one was left blank. "
End If) (
If me.tickbox2.valuse = 0 then
me.tectbox1.value = "tickbox two was left blank. "
end if.)
End sub

but vb in access does not allow me to do this saying there is an expression missing.

As i have quite a few more than 2 tick boxes on the form, i do not want to create an if statement for each combonation of the tickboxes. Is there a way that i can do this without using a different if statement for each combonation?
 
Something like:

Code:
If me.tickbox1 = 0 and me.tickbox2 = 0 then
    me.textboxone = "Tickbox one and two were blank"
else if me.tickbox1 = 0 then
    me.textboxone = "Tickbox one is blank"
else if me.tickbox2 = 0 then
    me.textboxone = "Tickbox two is blank"
end if
 
thanks for the quick reply ken.

I was thinking it would be something like that.

The thing with my database is that there is 20+ tickboxes, so thats going to be a huge statement to go through all combomations, and i just dont trsut myself to go through them all wihtout missing any.

I was hoping for it to be something easy like putting an if statement for teh value like i this:

Pseudo:
text box value equals ((if tickbox1 = unticked, return "tickbox 1 is unticked) " " (if tickbox2 = unticked, return "tickbox 2 is unticked))

This way the status of any tickbox which is unticked will append itself to the end of the textbox's current value.

Is this possible?
 
I'm kind of missing the point of this drill from a higher perspective. So if you have some check boxes and some are checked and some are not, isn't that kind of the usefullness of them?

Or - Is what you want is for all of them them to be checked before some other pc of logic is executed?
 
How about this, its non tested air code.

Dim Txt1 as String
Dim Txt2 as string

Txt1=" "
Txt2=" "

If me.tickbox1 = 0 Then Txt1 = "Tickbox one is blank "
If me.tickbox2 = 0 Then Txt2= "Tickbox two is blank"
me.Textboxone= Txt1 & Txt2


Brian
 
Or - Is what you want is for all of them them to be checked before some other pc of logic is executed?

thats exactly what i tried to say, im not good with wording, sorry.

i have not got too much pratical knowledge of VB at the moment, just what university has tought me in controlled senerios and what i am learning on my own, but i have not come accross this type of senerio before so i thought i would ask some people who know more :)

Your piece of advice brians seems like it could work, i will give it ago later and see what happens.

thanks for both your help so far.
 
In regards to doing this in a loop, here is and example:
Code:
Dim intCnt As Integer
Dim strMsg As String
Dim strConvert As String
Dim bolErrFound as Boolean
strCovert = "one, two, three, four, five, six, etc"
bolErrFound = False
intCnt = 1
Do Until intCnt > 20
     If Me("Tickbox" & intCnt) = 0 Then 
        if bolErrFound = True Then strMsg = strMsg & " and "
        strMsg = strMsg & "Tickbox " & _
                  Split(strConvert, ",", , vbTextCompare)(intCnt) & " was left blank"
        bolErrFound = True
     end if
     intCnt = intCnt + 1
Loop
Me.Message = strMsg
 
Last edited:
I have a solution, was alot simplier than i was thinking, thanks!

I couldnt do what you suggested magicman as i did not design this database, and i cant change the names of the tickbox incase other areas of the database is dependant on those names. iI used tick1 tick2 etc for an example only. nice loop though, will keep it in mind if i design something like this myself.

Brian your advice worked, I conbined it with part of what magicman suggested, it now lookes like the following:

Code:
dim text1, text2, text3, text 4 as string
 
if me.tick1.value = 0 then
me.textbox = textbox & "Tickbox one is unticked. "
end if
if me.tick2.value = 0 then
me.textbox = textbox & "Tickbox two is unticked. "
end if
if me.tick3.value = 0 then
me.textbox = textbox & "Tickbox three is unticked. "
end if
if me.tick4.value = 0 then
me.textbox = textbox & "Tickbox four is unticked. "
end if

this now prints my desired results if all tickboxes are unitcked:
Tickbox one is unticked. Tickbox two is unticked. Tickbox three is unticked. Tickbox four is unticked.

the button keeps adding the same text to the end of textbox if it is continually pressed, so i added another button to clear the textbox on clicking to resolve this, for some reason adding "me.textbox.value = null" at the start of the click event for the above button does not erase the current contents when clicked.

Thanks for all your help guys.
 
Cool. Maybe put a vbcrlf in there as well:

me.textbox = textbox & "Tickbox one is unticked. " & vbcrlf

etc...

???
 
Start with
me.textbox.value = " " or me.textbox.value = ""
to set the textbox to a blank or null .

Brian
 
your a star brian.

thanks for that command ken, didnt know it exsisted :(
 

Users who are viewing this thread

Back
Top Bottom