简体   繁体   中英

Fill in Text box field with text and concatenate text if multiple boxes are checked using Access 2013 vba

Can anyone help with an Access 2013 DB. I have one table and a form with seven check boxes with the days of the week, if a box is checked I would like it to fill in a text box field and concatenate with any other day that is checked. The way I have it done works, however, there has to be a better way than repeating the code for the seven days seven times. Any help or suggestions would be greatly appreciated.

Option Compare Database
Dim DMon As String
Dim DTue As String
Dim DWed As String
Dim DThur As String
Dim DFri As String
Dim DSat As String
Dim DSun As String
--------------------------------------------------------------
' **************** Monday ***********
Private Sub Day_Mon_Click()
If Me.Day_Mon = True Then
    DMon = "Monday/"
Else
    DMon = ""
End If
' ***************
If Me.Day_Tue = True Then
    DTue = "Tuesday/"
Else
    DTue ""
End If

Me.Days.Value = Dmon & DTue & DWed & DThur & DFri & DSat & DSun

End Sub
' *************** Tuesday **********
Private Sub Day_Tue_Click()
 If Me.Day_Mon = True Then
    DMon = "Monday/"
Else
    DMon = ""
End If
' ***************
If Me.Day_Tue = True Then
    DTue = "Tuesday/"
Else
    DTue ""
End If

Me.Days.Value = Dmon & DTue & DWed & DThur & DFri & DSat & DSun

End Sub

how about this in your Days textbox control source:

=iif(me.day_Mon = 1,"Monday/","") & iif(me.day_Tues = 1,"Tuesday/","") & iif() & iif() etc 

This will create the string you are after. you have to use '= 1' to test for the checkbox being checked or not, '= true' won't work here even though it does in vba.

HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM