+ Reply to Thread
Results 1 to 10 of 10

View 1st Record through User Form Automatically

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    View 1st Record through User Form Automatically

    Hi All,

    I have a User Form in Excel which is now working absorlutely perfect, with some help from you guys on here, I have one last question, When I click first Record on the form it display the very first record with Text in the spreadsheet, Can anyone show me how to have the first Records Data show automatically in the form when the form is launched?

    Also I have set Record 3 as the first record becasue 1 & 2 have the headers in them, but when I click previous record it still shows them, can i get around this somehow.

    Thanks Guys.

    Shazz
    x
    Last edited by Shazz; 02-03-2012 at 11:26 AM. Reason: Solved

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: View 1st Record through User Form Automatically

    Need to see the code, but it's not a good idea to use two rows for the header
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Re: View 1st Record through User Form Automatically

    Quote Originally Posted by royUK View Post
    Need to see the code, but it's not a good idea to use two rows for the header
    This is the complete code for the User Form.

    Dim Data As Worksheet
    
    Private Sub Add_Record_Click()
        ClearForm
        Frame5.Visible = True
        Frame4.Visible = False
        Add_Record.Enabled = False
        CommandButton1.Enabled = False
    End Sub
    
    Private Sub CheckBox1_Click()
    
    End Sub
    
    Private Sub CmdCancel_Click()
        ClearForm
        Frame4.Visible = True
        Frame5.Visible = False
        Add_Record.Enabled = True
        CommandButton1.Enabled = True
    End Sub
    
    Private Sub CmdClear_Click()
        ClearForm
    End Sub
    
    Private Sub CmdEnter_Click()
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        SaveData LastRow + 1
        ClearForm
    End Sub
    
    Private Sub ComboBox14_Change()
    
    End Sub
    
    Private Sub CommandButton1_Click()
        SaveData Val(RowNumber.Value)
    End Sub
    
    Private Sub First_Click()
        RowNumber.Value = 3
    End Sub
    
    Private Sub Frame5_Click()
    
    End Sub
    
    Private Sub InstallDate2_Change()
    
    End Sub
    
    Private Sub Last_Record_Click()
        LastRow = Data.Cells(Data.Rows.Count, 1).End(xlUp).Row
        RowNumber.Value = LastRow
    End Sub
    
    Private Sub Next_Record_Click()
        LastRow = Data.Cells(Data.Rows.Count, 1).End(xlUp).Row
        If RowNumber.Value = "" Then
            RowNumber = 1
            Exit Sub
        End If
        If Val(RowNumber.Value) < LastRow Then
            RowNumber.Value = Val(RowNumber.Value) + 1
        End If
    End Sub
    
    Private Sub Payment_Click()
    
    End Sub
    
    Private Sub Previous_Click()
        If Val(RowNumber.Value) > 1 Then
            RowNumber.Value = Val(RowNumber.Value) - 1
        End If
    End Sub
    
    Private Sub RowNumber_Change()
        LoadData Val(RowNumber.Value)
    End Sub
    
    Private Sub Save_Record_Click()
        LastRow = Data.Cells(Data.Rows.Count, 1).End(xlUp).Row
        SaveData LastRow + 1
        ClearForm
        Frame4.Visible = True
        Frame5.Visible = False
        Add_Record.Enabled = True
        CommandButton1.Enabled = True
    End Sub
    
    Private Sub TextBox10_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
        Dim R As Long
            
            R = CLng(RowNumber)
            
          ' There must be a row number and the user must left click with the mouse.
            If R <> 0 And Button = 1 Then
               On Error Resume Next
                  Data.Cells(R, 10).Hyperlinks(1).Follow True
                  If Err <> 0 Then MsgBox "Unable to open '" & Data.Cells(R, 10).Value & "'."
               On Error GoTo 0
            End If
    
    End Sub
    
    
    Private Sub TextBox11_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
        Dim R As Long
            
            R = CLng(RowNumber)
            
          ' There must be a row number and the user must left click with the mouse.
            If R <> 0 And Button = 1 Then
               On Error Resume Next
                  Data.Cells(R, 10).Hyperlinks(1).Follow True
                  If Err <> 0 Then MsgBox "Unable to open '" & Data.Cells(R, 10).Value & "'."
               On Error GoTo 0
            End If
    
    End Sub
    
    Private Sub TextBox12_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
        Dim R As Long
            
            R = CLng(RowNumber)
            
          ' There must be a row number and the user must left click with the mouse.
            If R <> 0 And Button = 1 Then
               On Error Resume Next
                  Data.Cells(R, 10).Hyperlinks(1).Follow True
                  If Err <> 0 Then MsgBox "Unable to open '" & Data.Cells(R, 10).Value & "'."
               On Error GoTo 0
            End If
    
    End Sub
    
    Private Sub UserForm_Initialize()
        Set Data = Sheets("Data Form")
    End Sub
    
    Sub ClearForm()
        Dim ctl As MSForms.Control
        ' Clear the form
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
                ctl.Value = ""
            ElseIf TypeName(ctl) = "CheckBox" Then
                ctl.Value = False
            End If
        Next ctl
    End Sub
    
    Sub LoadData(SelRow)
    
        With Data
            If SelRow < 1 Or SelRow > .Cells(.Rows.Count, 1).End(xlUp).Row Then
                Label13.Visible = True
                Exit Sub
            End If
            Label13.Visible = False
            For col = 1 To 12
                Controls("TextBox" & col).Value = .Cells(SelRow, col).Value
            Next col
            For col = 13 To 16
                Controls("ComboBox" & col).Value = .Cells(SelRow, col).Value
                Next col
            ComboBox13.Value = .Cells(SelRow, 13).Value
            ComboBox14.Value = .Cells(SelRow, 14).Value
            InstallDate.Value = .Cells(SelRow, 15).Value
            TextBox13.Value = .Cells(SelRow, 16).Value
            ComboBox15.Value = .Cells(SelRow, 17).Value
            ComboBox16.Value = .Cells(SelRow, 18).Value
            InstallDate2.Value = .Cells(SelRow, 19).Value
            CheckDueDate2.Value = .Cells(SelRow, 20).Value
            TextBox14.Value = .Cells(SelRow, 21).Value
                End With
    End Sub
    
    Sub SaveData(SelRow)
       'Write Data to Worksheet
        For col = 1 To 12
            Data.Cells(SelRow, col).Value = Controls("TextBox" & col).Value
        Next col
        Data.Cells(SelRow, 13).Value = ComboBox13.Value
        Data.Cells(SelRow, 14).Value = ComboBox14.Value
        Data.Cells(SelRow, 15).Value = InstallDate.Value
        Data.Cells(SelRow, 16).Value = TextBox13.Value
        Data.Cells(SelRow, 17).Value = ComboBox15.Value
        Data.Cells(SelRow, 18).Value = ComboBox16.Value
        Data.Cells(SelRow, 19).Value = InstallDate2.Value
        Data.Cells(SelRow, 20).Value = CheckDueDate2.Value
        Data.Cells(SelRow, 21).Value = TextBox14.Value
    End Sub

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: View 1st Record through User Form Automatically

    Not sure but looking through the SelRow could be overwriting RowNumber.

  5. #5
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Re: View 1st Record through User Form Automatically

    That doesn't really help me, I am very new at all this and most of the code has been given by people off the forum.

    Could someon advise what I need to do.

    Thanks.

    Shazz
    x

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: View 1st Record through User Form Automatically

    So you've not learned what the code is doing?

    Instead of posting all that code it would have been more useful to attach the workbook.

  7. #7
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Re: View 1st Record through User Form Automatically

    Sorry about that, as I said I am very new to all this.

    The Workbook is attached for you to look at.
    Attached Files Attached Files

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: View 1st Record through User Form Automatically

    I have not looked at the workbook but I think you jsut change the Previosu button code to
    Private Sub Previous_Click()
        If Val(RowNumber.Value) > 3 Then
            RowNumber.Value = Val(RowNumber.Value) - 1
        End If
    End Sub
    and then Userform_Initialize to
    Private Sub UserForm_Initialize()
        Set Data = Sheets("Data Form")
        RowNumber.Value = 3
    End Sub
    Good luck.

  9. #9
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Re: View 1st Record through User Form Automatically

    That did the trick, thanks so much you are a star.

    I have added to your Reputation.

    Shazz

  10. #10
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: View 1st Record through User Form Automatically

    My pleasure, and thank you.

    Please do not forget to mark the thread Solved. (see FAQ)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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