Consulting

Results 1 to 8 of 8

Thread: Solved: Checkbox correspondence

  1. #1

    Solved: Checkbox correspondence

    Hello,

    I have a user form that captures data and records to a spreadsheet. I have just added checkboxes on. Bascially i want the user to be able to tick a checkbox and then a column on the spreadsheet would fill with a letter. At the moment it displays "TRUE". Is there anyway to change this. I also use the form to display records so i need to work the opposite way aswell i.e. the value on the spreadsheet ticks the box on the userform when viewing records.

    [vba]

    Private Sub btnAddRecord_Click()
    'next empty cell in column A

    Set c = Range("a65536").End(xlUp).Offset(1, 0)
    Application.ScreenUpdating = False 'speed up, hide task

    If Not IsError(Application.Match(Val(Me.txtPersNum.Text), Sheets("Master Data").Columns(4), 0)) Then
    MsgBox "That Personnel Number is already assigned - try another", vbCritical, "Duplicate found"
    Else
    'update it
    'write userform entries to database
    c.Value = Me.ddlSurname.Value
    c.Offset(0, 1).Value = Me.ddlForename.Value
    c.Offset(0, 2).Value = Me.ddlAssignee.Value
    c.Offset(0, 3).Value = Me.txtPersNum.Value
    c.Offset(0, 4).Value = Me.ddlStartDate.Value
    c.Offset(0, 5).Value = Me.ddlEndDate.Value
    c.Offset(0, 6).Value = Me.ddlDivision.Value
    c.Offset(0, 7).Value = Me.ddlLocation.Value
    c.Offset(0, 8).Value = Me.ddlLineManager.Value
    c.Offset(0, 9).Value = Me.ddlVCS.Value
    c.Offset(0, 10).Value = Me.ddlHealth.Value
    c.Offset(0, 11).Value = Me.CheckBox1.Value

    Call ClearForm

    End If

    Application.ScreenUpdating = True
    End Sub
    [/vba]

    Any help is great. Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Surely, you check the checkbox value and load if

    [vba]

    If Me.CheckBox1.Value Then
    c.Offset(0, 11).Value = "X"
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    How does this work the other way then. For instance the code below, reads whats on the spreadsheet and displays it on the user form. How would i adapt this for my checkbox and value X?

    [VBA]Private Sub UpdateDetails()
    ddlSurname.Text = Cells(lCurrentRow, 1).Value
    ddlForename.Text = Cells(lCurrentRow, 2).Value
    ddlAssignee.Text = Cells(lCurrentRow, 3).Value
    txtPersNum.Text = Cells(lCurrentRow, 4).Value
    ddlStartDate.Text = Cells(lCurrentRow, 5).Value
    ddlEndDate.Text = Cells(lCurrentRow, 6).Value
    ddlDivision.Text = Cells(lCurrentRow, 7).Value
    ddlLocation.Text = Cells(lCurrentRow, 8).Value
    ddlLineManager.Text = Cells(lCurrentRow, 9).Value
    ddlVCS.Text = Cells(lCurrentRow, 10).Value
    ddlHealth.Text = Cells(lCurrentRow, 11).Value

    Call SetupButtons(False, False, True, False)
    End Sub[/VBA]

    THanks!!!!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Off the top

    [vba]

    Me.CheckBox1.Value = c.Offset(0, 11).Value = "X"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Gotchya Thnks

  6. #6
    Actually this does'nt work XLD. It just brings back a tick even when the cell doesn't have a "C" in it?

  7. #7
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location

    you have to use an event to change the checkbox.

    If you put a checkbox on a worksheet you'll see how the event changes the ticks on the checkbox. For a User form to do the same you'll need to tie the control you are using to look at the sheet to the checkbox.

    [VBA]
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Set Target = Range("a1")
    If Target.Value = "x" Then
    Me.CheckBox1 = True 'ticked
    Else
    Me.CheckBox1 = False 'unticked
    End If
    End Sub
    [/VBA]

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Works fine for me, sets and unsets according to the value of that cell, but it is looking for X not C.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •