Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-01-2009, 07:22 AM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Edit worksheet data thru userform

Please Register to Remove these Ads

Hi everyone,

Depending on the attached workbook,

How can I edit the employee's Name and badge number thru a userform?

What should we depend on to save the employee's name before changing it, in order to use it as a find key?

Thank you,
Attached Files
File Type: xls Edit data via Userform.xls (37.5 KB, 21 views)

Last edited by LoveCandle; 07-06-2009 at 07:49 AM.
Reply With Quote
  #2  
Old 07-01-2009, 01:37 PM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Derbyshire,UK
MS Office Version:Xp; 2007
Posts: 13,782
royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding
Re: Edit worksheet data thru userform

Take a look at the DataBaseForm example here

http://www.excel-it.com/vba_examples.htm
__________________
Hope that helps.

RoyUK
--------
If you are pleased with a member's answer then use the Scales icon to rate it

For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Remember to mark your questions Solved and rate the answer(s)


Code Tags: Make your code easier for us to read
Reply With Quote
  #3  
Old 07-01-2009, 04:14 PM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

Hi,

Thank you royUK for your useful link you posted,

I applied amendment code in the mentioned link database form example, but it didn't work with me.

Code:
Private Sub CommandButton1_Click()

If MyRange Is Nothing Then GoTo skip

For Each c In MyRange
    If r = 0 Then c.Select
    r = r - 1
Next c

skip:
    Set c = ActiveCell
    c.Value = ComboBox1
    c.Offset(0, 1).Value = TextBox1
    Application.ScreenUpdating = True
    On Error GoTo 0
    
End Sub
No errors appear, but the updates are inserted in the first row of the range only,, I don't know why!!!

Can you please find me a solution for that,,
Attached Files
File Type: xls Edit data via Userform2.xls (32.0 KB, 6 views)
Reply With Quote
  #4  
Old 07-02-2009, 02:33 AM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Derbyshire,UK
MS Office Version:Xp; 2007
Posts: 13,782
royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding
Re: Edit worksheet data thru userform

That code isn't from the example. What doesn't work?
__________________
Hope that helps.

RoyUK
--------
If you are pleased with a member's answer then use the Scales icon to rate it

For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Remember to mark your questions Solved and rate the answer(s)


Code Tags: Make your code easier for us to read
Reply With Quote
  #5  
Old 07-02-2009, 05:56 AM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

The code is derived from the example, the only difference is that I removed some lines, which I don't need in my code.

But, the problem now is that when I edit for example record No. 4 of my range .. the changes are inserted in record number 1 not 4 and so on.

I hope that you can find the reason behind that and solve the problem.

Thanks,
Reply With Quote
  #6  
Old 07-02-2009, 06:02 AM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Derbyshire,UK
MS Office Version:Xp; 2007
Posts: 13,782
royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding
Re: Edit worksheet data thru userform

You've set the code to work on the activecell, no one selected by the userform - that's how the code in the example works
__________________
Hope that helps.

RoyUK
--------
If you are pleased with a member's answer then use the Scales icon to rate it

For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Remember to mark your questions Solved and rate the answer(s)


Code Tags: Make your code easier for us to read
Reply With Quote
  #7  
Old 07-02-2009, 06:56 PM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

Hi,

Until now I coundn't understand how the code in example works exactly,,

What does (r) in the following part refer to?

Code:
For Each c In MyRange
    If r = 0 Then c.Select
    r = r - 1
Next c
It will be better for me if you correct my code's mistakes and post it?

Thank you,
Reply With Quote
  #8  
Old 07-03-2009, 04:49 PM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

Hi,

Can you please help me in this query, I really need the answer ASAP,

Thanks,
Reply With Quote
  #9  
Old 07-04-2009, 03:43 AM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Derbyshire,UK
MS Office Version:Xp; 2007
Posts: 13,782
royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding
Re: Edit worksheet data thru userform

Reading the original question, I'm not sure what you mean. Why do you want to save the name before editing it?
__________________
Hope that helps.

RoyUK
--------
If you are pleased with a member's answer then use the Scales icon to rate it

For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Remember to mark your questions Solved and rate the answer(s)


Code Tags: Make your code easier for us to read
Reply With Quote
  #10  
Old 07-04-2009, 07:22 AM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

Hi,

I believe that we have to save the original name in order for excel to use it as a find key for recognizing the concerned record that should be found and paste the new changes on it.

I hope that my idea is clear now,

Even in the Database example, when I tried to run the Amendment code Directly (Without running find code before it), the same problem appeared (the changes are inserted in record number 1 only) ..

Therefore, I think that there is a relationship between The example find code and amendment code .. but I don't know what is it exactly??!!!

Anyhow, if my belief is incorrect, I would be so thankful for you if you help me writing the suitable code for edit database records without pasting someone's data on another one's.

Moreover, it will nice from you if you can apply that on my previous attached workbook,

Thank you,

Last edited by LoveCandle; 07-04-2009 at 07:58 AM.
Reply With Quote
  #11  
Old 07-04-2009, 08:00 AM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Derbyshire,UK
MS Office Version:Xp; 2007
Posts: 13,782
royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding
Re: Edit worksheet data thru userform

The code in your first post does that - select a name from the combobox, edit the name or amend the textbox. Click Edit & the changes are recorded.
__________________
Hope that helps.

RoyUK
--------
If you are pleased with a member's answer then use the Scales icon to rate it

For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Remember to mark your questions Solved and rate the answer(s)


Code Tags: Make your code easier for us to read
Reply With Quote
  #12  
Old 07-04-2009, 08:54 AM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

Yes, the workbook in my first post does record the changes perfectly if we change the TexBox1 value only ,,

But once we change ComboBox1 value, the code returns an error, because the code looks for ComboBox1 value and doesn't find it in the database because it has been changed and the new value is not available in the database.

So, I think the solution is that we have to save ComboBox1 original value somewhere else, in order to use it for database search.

I hope that you got my idea now,

Thanks,
Reply With Quote
  #13  
Old 07-04-2009, 09:15 AM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Derbyshire,UK
MS Office Version:Xp; 2007
Posts: 13,782
royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding
Re: Edit worksheet data thru userform

Amend the Edit Button
Code:
Private Sub CommandButton1_Click()

    If MyRange Is Nothing Then GoTo skip

    For Each c In MyRange
        If r = 0 Then c.Select
        r = r - 1
    Next c

skip:
    Set c = ActiveCell
    c.Value = ComboBox1
    c.Offset(0, 1).Value = TextBox1
    'refresh list
    Unload Me
    UserForm1.Show
    Application.ScreenUpdating = True
    On Error GoTo 0

End Sub
__________________
Hope that helps.

RoyUK
--------
If you are pleased with a member's answer then use the Scales icon to rate it

For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Remember to mark your questions Solved and rate the answer(s)


Code Tags: Make your code easier for us to read
Reply With Quote
  #14  
Old 07-04-2009, 09:40 AM
LoveCandle LoveCandle is offline
Valued Forum Contributor
 
Join Date: 07 Nov 2005
Posts: 231
LoveCandle is becoming part of the community
Re: Edit worksheet data thru userform

Sorry royUK, there is no difference between your code's result and mine,

The problem is still existing .. the changes are still recorded in the first record.

Anyhow, I found a solution but it is not that much practical.

My trick solution is saving combobox value in a label (the label will be hidden), and the use the label value as a database search key,

See my attachment.

Thank you,
Attached Files
File Type: xls Edit data via Userform3.xls (31.5 KB, 10 views)
Reply With Quote
  #15  
Old 07-04-2009, 10:32 AM
royUK's Avatar
royUK royUK is offline
Forums Administrator
 
Join Date: 18 Nov 2003
Location: Derbyshire,UK
MS Office Version:Xp; 2007
Posts: 13,782
royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding royUK Has a higher level of understanding
Re: Edit worksheet data thru userform

I'm not at all sure what you mean, when you edit the list the userform is "refreshed" and the combobox updated with the changes.
__________________
Hope that helps.

RoyUK
--------
If you are pleased with a member's answer then use the Scales icon to rate it

For Excel consulting, free examples and tutorials visit my site
Check out the free Excel Toolbar

New members please read & follow the Forum Rules

Remember to mark your questions Solved and rate the answer(s)


Code Tags: Make your code easier for us to read
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump