+ Reply to Thread
Results 1 to 15 of 15

Userform Code Errors (broken by novice/fool)

Hybrid View

  1. #1
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Userform Code Errors (broken by novice/fool)

    Hello D.A.S.,

    Add this code to your UserForm1 code. This will display the first record when the form is displayed.
    Private Sub UserForm_Activate()
        SpinButton1.Value = 2
        TextBox7.Value = SpinButton1.Value
        ShowCurrentRecord
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  2. #2
    Registered User
    Join Date
    11-21-2013
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Userform Code Errors (broken by novice/fool)

    Hi Leith,

    I added the code to the UserForm1 code but now brings up the following error when the form is opened:

    
    Sub ShowCurrentRecord()
    
      Dim Wks As Worksheet
      
        Set Wks = ThisWorkbook.Worksheets(1)
       
        With UserForms(0)
       R = .SpinButton1.Value + 1
          .txtContName = Wks.Cells(R, "B").Value
          .txtClientFirstName = Wks.Cells(R, "C").Value
          .txtClientLastName = Wks.Cells(R, "D").Value
          .txtIntContDat = Wks.Cells(R, "E").Value
          .txtIntAssessDat = Wks.Cells(R, "F").Value
          .txtIntContComp = Wks.Cells(R, "G").Value
          .ComboContType = Wks.Cells(R, "H").Value
          .txtDisCost = Format(Wks.Cells(R, "I").Value, "Currency")
          .txtremCost = Format(Wks.Cells(R, "J").Value, "Currency")
          .txtTCSent.Value = Wks.Cells(R, "K").Value
          .txtTCRec.Value = Wks.Cells(R, "L").Value
          .ComboContStatus.Value = Wks.Cells(R, "M").Value
          .txtSiteUnitNo.Value = Wks.Cells(R, "N").Value
          .txtSiteStAdrs.Value = Wks.Cells(R, "O").Value
          .txtSiteSuburb.Value = Wks.Cells(R, "P").Value
          .txtSiteCity.Value = Wks.Cells(R, "Q").Value
          .txtPostUnitNo.Value = Wks.Cells(R, "R").Value
          .txtPostStAdrs.Value = Wks.Cells(R, "S").Value
          .txtSiteSuburb.Value = Wks.Cells(R, "T").Value
          .txtPostCity.Value = Wks.Cells(R, "U").Value
          .txtHomePh.Value = Wks.Cells(R, "V").Value
          .txtWorkPh.Value = Wks.Cells(R, "W").Value
          .txtMobPh.Value = Wks.Cells(R, "X").Value
          .txtEmail.Value = Wks.Cells(R, "Y").Value
          .txtPrinDis.Value = Wks.Cells(R, "Z").Value
          .txtPrinRem.Value = Wks.Cells(R, "AA").Value
          .txtAdCont1FNam.Value = Wks.Cells(R, "AB").Value
          .txtAdCont1LNam.Value = Wks.Cells(R, "AC").Value
          .txtAdCont1HomePh.Value = Wks.Cells(R, "AD").Value
          .txtAdCont1WorkPh.Value = Wks.Cells(R, "AE").Value
          .txtAdCont1MobPh.Value = Wks.Cells(R, "AF").Value
          .txtAdCont1Email.Value = Wks.Cells(R, "AG").Value
          .txtAdCont2FNam.Value = Wks.Cells(R, "AH").Value
          .txtAdCont2LNam.Value = Wks.Cells(R, "AI").Value
          .txtAdCont2HomePh.Value = Wks.Cells(R, "AJ").Value
          .txtAdCont2WorkPh.Value = Wks.Cells(R, "AK").Value
          .txtAdCont2MobPh.Value = Wks.Cells(R, "AL").Value
          .txtAdCont2Email.Value = Wks.Cells(R, "AM").Value
          .txtAdCont3FNam.Value = Wks.Cells(R, "AN").Value
          .txtAdCont3LNam.Value = Wks.Cells(R, "AO").Value
          .txtAdCont3HomePh.Value = Wks.Cells(R, "AP").Value
          .txtAdCont3WorkPh.Value = Wks.Cells(R, "AQ").Value
          .txtAdCont3MobPh.Value = Wks.Cells(R, "AR").Value
          .txtAdCont3Email.Value = Wks.Cells(R, "AS").Value
          .txtAdCont4FNam.Value = Wks.Cells(R, "AT").Value
          .txtAdCont4LNam.Value = Wks.Cells(R, "AU").Value
          .txtAdCont4HomePh.Value = Wks.Cells(R, "AV").Value
          .txtAdCont4WorkPh.Value = Wks.Cells(R, "AW").Value
          .txtAdCont4MobPh.Value = Wks.Cells(R, "AX").Value
          .txtAdCont4Email.Value = Wks.Cells(R, "AY").Value
          .txtNotes.Value = Wks.Cells(R, "AZ").Value
          .TextBox7.Value = .SpinButton1.Value
        End With
    
    End Sub
    In the above " R = .SpinButton1.Value + 1 " is highlighted when I debeg ....Thoughts?
    Last edited by Leith Ross; 11-22-2013 at 06:19 PM.

+ 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. Created a userform in VBA that worked beautifully yesterday and crashed Excel today!
    By willneal in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-31-2012, 11:47 AM
  2. [SOLVED] Average hours worked based on days worked during a pay cycle
    By jaycee66 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-14-2012, 06:27 PM
  3. Replies: 0
    Last Post: 05-14-2012, 05:36 PM
  4. Calculating basic hours worked, between a time range and premium hours worked
    By RoyLittle0 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-07-2012, 06:59 AM
  5. Replies: 0
    Last Post: 01-05-2012, 06:23 AM

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