+ Reply to Thread
Results 1 to 11 of 11

Userform for data entry

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Userform for data entry

    Hi, I have a userform where staff will go into "Add case" tab to enter data. After selecting Sample Type, entering Marking and Mortuary No, they will click "Add". This command will add the data into textbox16. One problem here is that the "Case assigned" number should remain as "DVI-00001" if "Add" command is clicked, such that the next data added into textbox16 will have "DVI-00001-002". The "Case assigned" number should change to "DVI-00002-001" if the "Prelog" command is clicked. I'm having problems trying to make that happen.

    Staff will carry on adding to the textbox based on how much data there is, after which, they will click Prelog. This command will add the data into the worksheet. I'm having problems trying to get the data from textbox16 into the worksheet. The data needs to be split into the respective rows and columns according to the same heading.

    Any help is appreciated
    Last edited by bqheng; 10-05-2016 at 09:37 PM.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Userform for data entry

    Your requirements are not entirely clear, but give these changes a try and let me know how it goes.

    Form initialize code:
    Private Sub UserForm_Initialize()
        MultiPage1.Value = 0
        Dim cUnique As Collection
        Dim rng As Range
        Dim cell As Range
        Dim vNum As Variant
        Dim i As Integer
        Dim strW As String
        Dim sh As Worksheet
        Dim lastrow As Long
        
        
        lastrow = Worksheets("Case Log").Range("A" & Rows.Count).End(xlUp).Offset(0).Row
        If lastrow > 1 Then
            Me.TextBox13.Value = "DVI-" & Format(Split(Cells(lastrow, "A"), "-")(1) + 1, "00000") & "-" & Format(1, "000")
        Else
            Me.TextBox13.Value = "DVI-" & Format(lastrow, "00000") & "-" & Format(lastrow, "000")
        End If
        Me.TextBox13.Enabled = False
        
        ...
        ...
    Add button code:
    Private Sub CommandButton12_Click()
    TextBox16.MultiLine = True
    With TextBox16
        .Text = .Text & vbCr & TextBox13.Text & " " & ComboBox6.Text & " " & TextBox6.Text & " " & TextBox15.Text
    End With
    ComboBox6.ListIndex = -1
    TextBox6.Text = vbNullString
    TextBox15.Text = vbNullString
    TextBox13.Value = "DVI-" & Format(Split(TextBox13.Value, "-")(1), "00000") & "-" & Format(Split(TextBox13.Value, "-")(2) + 1, "000")
    End Sub
    Prelog button code:
    Private Sub CommandButton3_Click()
        Dim iRow As Long
        Dim ws As Worksheet
        Dim myLines As Variant
    
    
        Set ws = Worksheets("Case Log")
         
        myLines = Split(TextBox16.Text, vbCr)
        
         'find first empty row in database
        iRow = ws.Cells(Rows.Count, 1) _
        .End(xlUp).Offset(1, 0).Row
         
         'copy the data to the database
        ws.Cells(iRow, 1).Value = Me.TextBox13.Text
        ws.Cells(iRow, 2).Resize(1 + UBound(myLines), 1).Value = myLines
        ws.Cells(iRow, 5).Value = Me.TextBox4.Text
        
        TextBox13.Value = "DVI-" & Format(Split(TextBox13.Value, "-")(1) + 1, "00000") & "-" & Format(1, "000")
        
        Me.TextBox14.Text = "NULL"
        Me.TextBox14.Enabled = False
        
    End Sub
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Re: Userform for data entry

    Hi millz, thank you for your help. The "Add" command has been resolved thanks to your code. The "Prelog" button still needs working on, due to my unclear description. When this button is clicked, the information in textbox16 should populate into the worksheet as follows:
    Case: DVI-00001-001 Sample Type: Bone Marking: 1234 Mortuary ID: M1234
    Case: DVI-00001-002 Sample Type: Body part Marking: 1235 Mortuary ID: M1235

    Hope this helps

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Userform for data entry

    Try these changes:
    Private Sub CommandButton12_Click()
    TextBox16.MultiLine = True
    With TextBox16
        If .Text <> "" Then
            .Text = .Text & vbCr & TextBox13.Text & " " & ComboBox6.Text & " " & TextBox6.Text & " " & TextBox15.Text
        Else
            .Text = TextBox13.Text & " " & ComboBox6.Text & " " & TextBox6.Text & " " & TextBox15.Text
        End If
    End With
    ComboBox6.ListIndex = -1
    TextBox6.Text = vbNullString
    TextBox15.Text = vbNullString
    TextBox13.Value = "DVI-" & Format(Split(TextBox13.Value, "-")(1), "00000") & "-" & Format(Split(TextBox13.Value, "-")(2) + 1, "000")
    End Sub
    Private Sub CommandButton3_Click()
        Dim iRow As Long, i As Long
        Dim ws As Worksheet
        Dim myLines As Variant, v
    
    
        Set ws = Worksheets("Case Log")
         
        myLines = Split(TextBox16.Text, vbCrLf)
        
         'find first empty row in database
        iRow = ws.Cells(Rows.Count, 1) _
        .End(xlUp).Offset(1, 0).Row
         
         'copy the data to the database
        For i = 0 To UBound(myLines)
            v = Split(myLines(i), " ")
            ws.Cells(iRow, 1).Resize(, 4).Value = Array(v(0), v(1), v(3), v(2))
            ws.Cells(iRow, 5).Value = Me.TextBox14.Text
            iRow = iRow + 1
        Next
        TextBox16.Text = ""
        
        TextBox13.Value = "DVI-" & Format(Split(TextBox13.Value, "-")(1) + 1, "00000") & "-" & Format(1, "000")
        
        Me.TextBox14.Text = "NULL"
        Me.TextBox14.Enabled = False
        
    End Sub
    Edit:
    It will not populate properly if you choose "Body Part", since it contains a space.
    You can try a different column separator, like underscore ( _ )
    or revamp your form and use multi-column listbox instead of a multi-line textbox.
    Last edited by millz; 09-28-2016 at 03:15 AM.

  5. #5
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Re: Userform for data entry

    I tried the codes and got an invalid or unqualified reference on this line in red

    Private Sub CommandButton12_Click()
    TextBox16.MultiLine = True
    If .Text <> "" Then
            .Text = .Text & vbCr & TextBox13.Text & " " & ComboBox6.Text & " " & TextBox6.Text & " " & TextBox15.Text
        Else
            .Text = TextBox13.Text & " " & ComboBox6.Text & " " & TextBox6.Text & " " & TextBox15.Text
        End If

  6. #6
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Userform for data entry

    You need the With statement block, don't remove them.
    Private Sub CommandButton12_Click()
    TextBox16.MultiLine = True
    With TextBox16
        If .Text <> "" Then
            .Text = .Text & vbCr & TextBox13.Text & " " & ComboBox6.Text & " " & TextBox6.Text & " " & TextBox15.Text
        Else
            .Text = TextBox13.Text & " " & ComboBox6.Text & " " & TextBox6.Text & " " & TextBox15.Text
        End If
    End With

  7. #7
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Re: Userform for data entry

    Oh silly me... Thanks for correcting. I attached a revised version of the previous workbook. After users have filled in info, clicked "Add" and clicked "Receive in lab", how do I code the "transfer custody" button such that what is in textbox16 will have the correct custodian? example:
    Textbox16 has these info
    Case: DVI-00001-001 Sample Type: Bone Marking: 1234 Mortuary ID: M1234
    Case: DVI-00001-002 Sample Type: Body part Marking: 1235 Mortuary ID: M1235
    Clicking "Receive in Lab" will transfer these info into respective columns in worksheet. Column E will be populated with textbox14.
    Now users need to transfer the custody to another person or location. They do so by selecting from combobox5 and click "Execute". Column F should populate the new custodian for DVI-00001-001 and DVI-00001-002
    Last edited by bqheng; 10-05-2016 at 09:38 PM.

  8. #8
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Userform for data entry

    Try this change:

    Private Sub CommandButton10_Click()
        Application.ScreenUpdating = False
        Dim ws As Worksheet
        Dim lastrow As Long
        Dim r As Long, v, i As Long
         
        Set ws = Worksheets("Case Log")
        
        v = Split(TextBox16.Text, vbCrLf)
        
        lastrow = ws.Range("A1000").End(xlUp).Row
        For i = 0 To UBound(v)
            For r = 2 To lastrow
        
                If ws.Cells(r, 1) = Split(v(i), " ")(0) Then
        
                    ws.Cells(r, 6).Value = ComboBox5.Value
                     
                End If
            Next r
        Next
        Application.ScreenUpdating = True
        
        TextBox14.Text = ComboBox5.Value
        ComboBox5.Value = ""
    
    End Sub

  9. #9
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Re: Userform for data entry

    Thanks millz. Next question: In the "Case manager" tab, how do I get combobox2 to populate the cases that are entered in column A, without repetitions? And after selecting the case number from the combobox, how do I get data from columns C to H into textbox18 for that particular case?

  10. #10
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Userform for data entry

    Hi, you are deviating further from the original topic with subsequent problems/questions.

    I suggest closing this thread and opening a new one with your new problem. Fresh threads usually get help faster, and possibly better solutions too.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

    If you think that I could be of help, you can PM me a link to your new thread containing the new question, and I will take a look when time permits.

  11. #11
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Re: Userform for data entry

    sorry about that millz. will start a new thread. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform data entry
    By stevipop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2014, 04:12 PM
  2. userform and data entry help
    By andrewode in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2014, 11:30 AM
  3. Replies: 0
    Last Post: 02-04-2014, 12:36 AM
  4. Userform data entry
    By amekock in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-19-2011, 10:26 AM
  5. Data entry using a userform
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2010, 08:59 PM
  6. UserForm for data entry
    By jay11 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-2010, 03:30 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1