+ Reply to Thread
Results 1 to 11 of 11

VBA Scripting Help!!

Hybrid View

hnoshea VBA Scripting Help!! 10-15-2006, 11:41 AM
Simon Lloyd Hi in the code you supplied... 10-15-2006, 05:57 PM
hnoshea Not clear 10-15-2006, 07:15 PM
Charles vba help 10-15-2006, 07:35 PM
hnoshea help - still can't get it to... 10-15-2006, 08:20 PM
  1. #1
    Registered User
    Join Date
    10-03-2006
    Posts
    15

    Exclamation VBA Scripting Help!!

    New user of VBA and need help!!

    I downloaded a template from Contextures.com that contained a Userform for Parts Inventory. I am trying to change the form and datasheet to contain the fields I need to calculate and have somewhere along the line missed something. I can't get the form to operate.

    Anyone want to help me with this form? I can send it via email...

    Visual copies of code and form attached...

    Thanks

    Option Explicit

    Private Sub cmmAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("PartsData")

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

    'check for a part number
    If Trim(Me.vin.Value) = "" Then
    Me.vin.SetFocus
    MsgBox "Please enter a VIN number"
    Exit Sub
    End If

    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.FirstName.Value
    ws.Cells(iRow, 2).Value = Me.LastName.Value
    ws.Cells(iRow, 3).Value = Me.EnterCurrentDate.Value
    ws.Cells(iRow, 4).Value = Me.StreetAddress.Value
    ws.Cells(iRow, 5).Value = Me.City.Value
    ws.Cells(iRow, 6).Value = Me.state.Value
    ws.Cells(iRow, 7).Value = Me.Zip.Value
    ws.Cells(iRow, 8).Value = Me.phone.Value
    ws.Cells(iRow, 9).Value = Me.fax.Value
    ws.Cells(iRow, 10).Value = Me.email.Value
    ws.Cells(iRow, 11).Value = Me.vin.Value
    ws.Cells(iRow, 12).Value = Me.make.Value
    ws.Cells(iRow, 13).Value = Me.model.Value
    ws.Cells(iRow, 14).Value = Me.odometer.Value
    ws.Cells(iRow, 15).Value = Me.Engine.Value
    ws.Cells(iRow, 16).Value = Me.Serial.Value
    ws.Cells(iRow, 17).Value = Me.transmission.Value
    ws.Cells(iRow, 18).Value = Me.transserial.Value
    ws.Cells(iRow, 19).Value = Me.driveline.Value
    ws.Cells(iRow, 20).Value = Me.FanClutch.Value
    ws.Cells(iRow, 21).Value = Me.EaseyPedal.Value
    ws.Cells(iRow, 22).Value = Me.solo.Value
    ws.Cells(iRow, 23).Value = Me.dca.Value
    ws.Cells(iRow, 24).Value = Me.nalcool.Value
    ws.Cells(iRow, 25).Value = Me.amps.Value
    ws.Cells(iRow, 26).Value = Me.batteries.Value
    ws.Cells(iRow, 27).Value = Me.cca.Value
    ws.Cells(iRow, 28).Value = Me.idle.Value
    ws.Cells(iRow, 29).Value = Me.electrical.Value
    ws.Cells(iRow, 30).Value = Me.tire1.Value
    ws.Cells(iRow, 31).Value = Me.tire2.Value
    ws.Cells(iRow, 32).Value = Me.tire3.Value
    ws.Cells(iRow, 33).Value = Me.tire4.Value
    ws.Cells(iRow, 34).Value = Me.tire5.Value
    ws.Cells(iRow, 35).Value = Me.tire6.Value
    ws.Cells(iRow, 36).Value = Me.tire7.Value
    ws.Cells(iRow, 37).Value = Me.tire8.Value
    ws.Cells(iRow, 38).Value = Me.tire9.Value
    ws.Cells(iRow, 39).Value = Me.tire10.Value
    ws.Cells(iRow, 40).Value = Me.tire11.Value
    ws.Cells(iRow, 41).Value = Me.tire12.Value
    ws.Cells(iRow, 42).Value = Me.tire13.Value
    ws.Cells(iRow, 43).Value = Me.tire14.Value
    ws.Cells(iRow, 44).Value = Me.tire15.Value
    ws.Cells(iRow, 45).Value = Me.tiresize.Value
    ws.Cells(iRow, 46).Value = Me.tiremanu.Value
    ws.Cells(iRow, 47).Value = Me.miles.Value
    ws.Cells(iRow, 48).Value = Me.mpg.Value
    ws.Cells(iRow, 49).Value = Me.axle.Value
    ws.Cells(iRow, 50).Value = Me.pm.Value


    'clear the data
    Me.FirstName.Value = ""
    Me.LastName.Value = ""
    Me.EnterCurrentDate.Value = ""
    Me.StreetAddress.Value = ""
    Me.City.Value = ""
    Me.state.Value = ""
    Me.Zip.Value = ""
    Me.phone.Value = ""
    Me.fax.Value = ""
    Me.email.Value = ""
    Me.vin.Value = ""
    Me.make.Value = ""
    Me.model.Value = ""
    Me.odometer.Value = ""
    Me.Engine.Value = ""
    Me.Serial.Value = ""
    Me.transmission.Value = ""
    Me.transserial.Value = ""
    Me.driveline.Value = ""
    Me.FanClutch.Value = ""
    Me.EaseyPedal.Value = ""
    Me.solo.Value = ""
    Me.dca.Value = ""
    Me.nalcool.Value = ""
    Me.amps.Value = ""
    Me.batteries.Value = ""
    Me.cca.Value = ""
    Me.idle.Value = ""
    Me.electrical.Value = ""
    Me.tire1.Value = ""
    Me.tire2.Value = ""
    Me.tire3.Value = ""
    Me.tire4.Value = ""
    Me.tire5.Value = ""
    Me.tire6.Value = ""
    Me.tire7.Value = ""
    Me.tire8.Value = ""
    Me.tire9.Value = ""
    Me.tire10.Value = ""
    Me.tire11.Value = ""
    Me.tire12.Value = ""
    Me.tire13.Value = ""
    Me.tire14.Value = ""
    Me.tire15.Value = ""
    Me.tiresize.Value = ""
    Me.tiremanu.Value = ""
    Me.miles.Value = ""
    Me.mpg.Value = ""
    Me.axle.Value = ""
    Me.pm.Value = ""
    Me.vin.SetFocus
    End Sub

    Private Sub cmdAdd_Click()

    End Sub

    Private Sub cmdClose_Click()
    Unload Me
    End Sub

    Private Sub ComboBox1_Change()

    End Sub

    Private Sub Label1_Click()

    End Sub

    Private Sub Label11_Click()

    End Sub

    Private Sub Label17_Click()

    End Sub

    Private Sub ListBox1_Click()

    End Sub

    Private Sub TextBox61_Change()

    End Sub

    Private Sub UserForm_QueryClose(Cancel As Integer, _
    CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
    Cancel = True
    MsgBox "Please use the button!"
    End If
    End Sub
    Attached Images Attached Images

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Hi in the code you supplied there is no "call" on the userform, somewhere in your code that starts everything off you need the line
    UserForm1.Show
    provided it is called UserForm1.

    You dont need all the empty modules, like
    Private Sub cmdAdd_Click()
    
    End Sub
    if you want to show the userform from within its own module then you would use
    Me.Show
    hope this helps,
    Regards,
    Simon

  3. #3
    Registered User
    Join Date
    10-03-2006
    Posts
    15

    Not clear

    I might need to make myself a little clearer. I created the form and it opens OK and I created a command button to open the form in Excel. my problem is I can't get the fields I created to feed into a second worksheet within the same workbook. I want the "Add this client" command button to enter the information on the form into the second worksheet and then when you choose the "close form" command button, I want it to erase any data entered into the form. Each time you use the "Add this client" command button it enters that information into a new row in the second worksheet.

    Any ideas now??

  4. #4
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    vba help

    Hi,

    This may help I didn't use all of you variables.
    This should find an empty row and post the userform data to the sheet
    that you need to name where indicated.



    Private Sub cmmAdd_Click()
    Application.ScreenUpdating = False
    Dim lrow As Long
    
    '''' This get the last empty cell in column "A"
    lrow = Sheets("yousheetname").Range("A65336").End(xlUp).Row + 1
    '''''This will populate to second sheet''
    Sheets("yoursheetname").Activate
    With Sheets("yoursheetname")
        ws.Cells(lrow, 1).Value = Me.FirstName.Value
        ws.Cells(lrow, 2).Value = Me.LastName.Value
        ws.Cells(lrow, 3).Value = Me.EnterCurrentDate.Value
        ws.Cells(lrow, 4).Value = Me.StreetAddress.Value
    '''''''''' the rest of your code '''''
    
    
    End With
    Application.ScreenUpdating = True
    End Sub
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  5. #5
    Registered User
    Join Date
    10-03-2006
    Posts
    15

    help - still can't get it to work...

    Private Sub cmmAdd_Click()
    Application.ScreenUpdating = False
    Dim lrow As Long

    lrow = Sheets("PartsData").Range("A65336").End(xlUp).Row + 1

    Sheets("PartsData").Activate
    With Sheets("PartsData")
    PartsData is the name of the worksheet that I want to use to fill up the data. NewClientInfo is the page that contains the link to the form. The form is listed as frmParts.

    What did i get wrong??

  6. #6
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Hnoshea, without you actually telling us what is not working, what errors you get and how far the sequence went before causing a problem we will find it difficult to help!

    Regards,
    Simon

+ 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