checkbox add/remove field string value

antonyx

Arsenal Supporter
Local time
Today, 18:07
Joined
Jan 7, 2005
Messages
556
hi.. i have a tickbox that when ticked adds
' (M&G)' to the end of my jobfrom field.. here is the code..

Code:
Private Sub JobMg_Click()
Me.txtjobfrom = Me.txtjobfrom & " (M&G)"
End Sub

so the job from field will contain

This House

you tick the box and it displays..

This House (M&G)

which is fine.. but when you click it again.. (and the checkbox value is false)
it does this..

This House (M&G) (M&G)

the rule is that if that checkbox is ticked.. then the jobfrom field will always contain the string ' (M&G) inside it..

so if i untick the checkbox.. how can i change that code so that it acknowledges the field already contains the ' (M&G)' and therefore removes it..?
 
as there is meaning to the data I would actually bind the check box to the main table and add the (M&G) bit for display only.

the way you have it you need to use the right() function to check if it already contains (M&G) before acting. you can use a combination of left() and Len() functions to do the trimming.

Peter
 
ok i think i need a bit of help on this one..

i have created a database with one table and one form..

http://www.londonheathrowcars.com/chkform.jpg

mg = Meet & Greet
os = Meet Ouside

these are important so i will be storing their true of false values aswell as adding the string to the place field.

only one of the tickboxes can be true.. never ever both.. so i have this code at the moment..

Code:
Option Compare Database

Private Sub chkmg_AfterUpdate()
If Me.chkmg.Value = True Then
Me.txtplace = Me.txtplace & " (M&G)"
Me.chkos.Value = False
End If
End Sub

Private Sub chkos_AfterUpdate()
If Me.chkos.Value = True Then
Me.txtplace = Me.txtplace & " (Outside)"
Me.chkmg.Value = False
End If
End Sub

after each checkbox is updated.. it ensures that if the value is true.. the string is passed and the other checkbox becomes false

however.. as you can imagine.. this method does ensure only one can be true.. but if i press them both 2 times then this happens..

http://www.londonheathrowcars.com/chkform2.jpg

so can you show me in the code how i can use the functions you mentioned..

so i have a place called Heathrow Airport.. if i tick mg then it will display Heathrow Airport (M&G).. if i untick mg then it will display Heathrow Airport

the os tickbox will need to do the same thing..

also.. if the place field currently displays Heathrow Airport (M&G).. and i tick the os tickbox.. it should change the place field to Heathrow Airport (Outside)

thanks.
 
antonyx said:
ok i think i need a bit of help on this one..

i have created a database with one table and one form..

http://www.londonheathrowcars.com/chkform.jpg

mg = Meet & Greet
os = Meet Ouside

these are important so i will be storing their true of false values aswell as adding the string to the place field.

only one of the tickboxes can be true.. never ever both.. so i have this code at the moment..

Code:
Option Compare Database

Private Sub chkmg_AfterUpdate()
If Me.chkmg.Value = True Then
Me.txtplace = Me.txtplace & " (M&G)"
Me.chkos.Value = False
End If
End Sub

Private Sub chkos_AfterUpdate()
If Me.chkos.Value = True Then
Me.txtplace = Me.txtplace & " (Outside)"
Me.chkmg.Value = False
End If
End Sub

after each checkbox is updated.. it ensures that if the value is true.. the string is passed and the other checkbox becomes false

however.. as you can imagine.. this method does ensure only one can be true.. but if i press them both 2 times then this happens..

http://www.londonheathrowcars.com/chkform2.jpg

so can you show me in the code how i can use the functions you mentioned..

so i have a place called Heathrow Airport.. if i tick mg then it will display Heathrow Airport (M&G).. if i untick mg then it will display Heathrow Airport

the os tickbox will need to do the same thing..

also.. if the place field currently displays Heathrow Airport (M&G).. and i tick the os tickbox.. it should change the place field to Heathrow Airport (Outside)

thanks.

I believe all you need to do is add code and tell it what to do if the value is false. Because it doesn't know what to do if the value is false (IE get reset), when both are false (after updates) they aren't reset.
 
only one of the tickboxes can be true.. never ever both.
Then use an option group! This will prevent both from being selected. If having neither selected is OK then you use a 3 choice option box.
I will attach a sample db as it easier than trying to explain :)

Peter
 

Attachments

yes.. thank you..

before i was only interested in the string value displaying on the report so my operator could tell how the driver should meet the passenger..

its all good now.. i have used ur method.. thanks bat!
 
it has the added advantage of making it easy to filter when someone wants statistics :)

Peter
 

Users who are viewing this thread

Back
Top Bottom