user745778
user745778

Reputation: 97

Multiple IF Then results into one textbox

In Access 2007 VB, is it possible combine the results of multiple If Then statements into one textbox? This code produces three results but I need the three combined into txtLOB at the end.

Private Sub Report_Load()

    If CSBB <> "No Impact" Then
        txtCSBB = "CSSB"
    End If

    If HL <> "No Impact" Then
        txtHL = "HL"
    End If

    If GWIM <> "No Impact" Then
        txtGWIM = "GWIM"
    End If

    txtLOB.Text = txtCSSB.Text & txtHL.Text & txtGWIM.Text

End Sub

Upvotes: 0

Views: 620

Answers (2)

Rachel Hettinger
Rachel Hettinger

Reputation: 8442

If you are looking to avoid the extra three textboxes, try this:

Private Sub Report_Load()
    Dim sText As String

    If CSBB <> "No Impact" Then
        sText = "CSSB"
    End If
    If HL <> "No Impact" Then
        sText = sText & "HL"
    End If
    If GWIM <> "No Impact" Then
        sText = sText & "GWIM"
    End If

    txtLOB = sText

End Sub

Upvotes: 2

Fionnuala
Fionnuala

Reputation: 91376

Yess, it is. Skip 'text'

txtLOB = txtCSSB & txtHL & txtGWIM

If these are the names of textboxes on the form for which this is the module, best use Me:

Me.txtLob

You can only use the .text property for the textbox that has the focus, and it refers to the current contents, not necessarily the same as the .value property.

Upvotes: 2

Related Questions