+ Reply to Thread
Results 1 to 2 of 2

VBA code to insert data from form

  1. #1
    Registered User
    Join Date
    08-14-2009
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    25

    VBA code to insert data from form

    I have a vba userform in a workbook that I obviously want to add data to a worksheet with in the document.

    When the submit button is clicked - an error message appears which reads:
    Compile error cannot find project or library.

    Im afraid the workbook file is too big to upload but here is my code which im hoping the error is in. The red text is what the debugger highlights when the error is displayed.

    Private Sub chkbranch_Click()
    If true value = "B"
    End Sub

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Worklog")

    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row

    'check for a repit code number
    If Trim(Me.txtref.Value) = "" Then
    Me.txtref.SetFocus
    MsgBox "Please enter a Repit Code"
    Exit Sub
    End If

    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.txtref.Value
    ws.Cells(iRow, 2).Value = DateValue(txtdate.Value)
    ws.Cells(iRow, 3).Value = Me.txtbranch.Value
    ws.Cells(iRow, 4).Value = Me.txtproperty.Value
    ws.Cells(iRow, 5).Value = Me.lststatus.Value
    ws.Cells(iRow, 6).Value = Me.lstaction.Value
    ws.Cells(iRow, 8).Value = DateValue(txtchase.Value)
    ws.Cells(iRow, 9).Value = Me.txtinitial.Value
    ws.Cells(iRow, 10).Value = Me.txtcomment.Value

    'clear the data
    Me.txtref.Value = ""
    Me.txtdate.Value = ""
    Me.txtbranch.Value = ""
    Me.txtproperty.Value = ""
    Me.lststatus.Value = ""
    Me.lstaction.Value = ""
    Me.txtchase.Value = ""
    Me.txtinitial.Value = ""
    Me.txtcomment.Value = ""
    Me.txtref.SetFocus

    End Sub

    Private Sub cmdClose_Click()
    Unload Me
    End Sub




    Private Sub Label5_Click()

    End Sub

    Private Sub txtactionyes_Click()

    End Sub

    Private Sub lstaction_Change()

    End Sub


    Private Sub lststatus_Click()

    End Sub

    Private Sub txtbranch_Click()

    End Sub

    Private Sub txtchase_Change()

    End Sub

    Private Sub txtdate_Change()

    End Sub

    Private Sub txtref_Change()

    End Sub

    Private Sub UserForm_Click()

    End Sub

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: VBA code to insert data from form

    Your post does not comply with the Forum Rules regarding use of code tags. All VBA code must be wrapped in code tags.

    Please amend your post and add the code tags, after which solutions to your question will be suggested.

    Rule #3
    Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button. For more information about these and other tags, click here.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

+ 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