+ Reply to Thread
Results 1 to 5 of 5

VBA - UserForm error

  1. #1
    Registered User
    Join Date
    03-15-2018
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    4

    VBA - UserForm error

    Hi,

    This is screencapture of a simple userform I have created:

    ScreenHunter 20180626 Image 004.jpg

    I want the data for txtName, txtID, txtEmailAddress and txtMobileNumber to be added to LastRow +1 of wsDatabase

    This is the code I have written for the command button "Add New":

    Private Sub cmdAddNew_Click()

    Dim LastCell As Range
    Dim txtName, txtEmailAddress As String
    Dim txtID, txtMobileNumber As Long

    Set LastCell = wsDatabase.Cells(Rows.Count, 1).End(xlUp)

    With LastCell

    .Offset(1, 0) = txtName
    .Offset(1, 1) = txtID
    .Offset(1, 2) = txtEmailAddress
    .Offset(1, 3) = txtMobileNumber

    End With

    End Sub

    After running the macro, this is the result (only Column D is updated with "0", Columns A to C not updated)

    ScreenHunter 20180626 Image 008.jpg

    Can I ask what am I not doing right? Thank you.
    Last edited by asd456; 06-26-2018 at 11:27 AM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA - UserForm error

    From what I can see, you are dimming string variables, and then using them to update your sheet. But I see no code that assigns a value to those strings, so you are pasting blanks. D is getting a 0 because txtMobileNumber is a "Long" variable and thus has a value of 0 by default. If txtName, txtID, txtEmailAddress, and txtMobileNumber are the names of your textboxes then in your code remove:

    Please Login or Register  to view this content.
    And change:

    Please Login or Register  to view this content.
    to:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA - UserForm error

    asd, Thanks for trying to add rep, based on your comment there this does solve your problem? I ask because you gave me negative rep instead of positive, and am hoping that was just a mistake?

  4. #4
    Registered User
    Join Date
    03-15-2018
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA - UserForm error

    Sorry, I wanted to give you good rep, how do I undo the bad rep and revise it to good rep instead? Thank you.

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA - UserForm error

    No worries! Can't be undone by anyone but an admin... it really is no big deal, as long as you were satisfied with the solution
    Thanks though.

+ 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. Error trying to import userform into Outlook: Unable to load UserForm.FRX
    By jeffclanders in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-08-2016, 12:36 PM
  2. Userform error
    By Jessica.Bush in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-14-2010, 01:29 AM
  3. VBA Userform error
    By bobo6429 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-12-2009, 10:13 AM
  4. Error in userform when error in worksheet
    By sepandb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2008, 10:43 AM
  5. Error with userform
    By Josh_123456 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-08-2007, 06:17 PM
  6. error in userform
    By damorrison in forum Excel General
    Replies: 6
    Last Post: 04-23-2006, 10:25 AM
  7. userform error
    By reuben in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2005, 06:20 PM

Tags for this Thread

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