Consulting

Results 1 to 13 of 13

Thread: Sleeper: Updating data in a spreadsheet with User Form?

  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location

    Exclamation Sleeper: Updating data in a spreadsheet with User Form?

    Hi,

    is there anybody who can help me how to update spreadsheet rows with a user form in excel?

    thanx

    det

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by det60
    Hi,

    is there anybody who can help me how to update spreadsheet rows with a user form in excel?

    thanx

    det
    Probably about 100. Give some details.

  3. #3
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    Details of my user form to copy multiple entries into DB1:

    'copy the data to the DB1 
    With wksPartsData
    .Cells(iRow, 1).Value = Me.cboPartid.Value
    .Cells(iRow, 2).Value = Me.cboPart.Value
    .Cells(iRow, 3).Value = Me.txtLoc.Value
    .Cells(iRow, 4).Value = Me.txtDate.Value
    .Cells(iRow, 5).Value = Me.txtPrice.Value
    End with

    Now i need to update or change some values in DB1 by using another user form. How can the user form find the row of the entry with all the informations which has to be changed?

    Thanx
    det
    Last edited by johnske; 07-09-2005 at 03:34 AM. Reason: insert VBA tags

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by det60
    Details of my user form to copy multiple entries into DB1:

    'copy the data to the DB1 
    With wksPartsData
    .Cells(iRow, 1).Value = Me.cboPartid.Value
    .Cells(iRow, 2).Value = Me.cboPart.Value
    .Cells(iRow, 3).Value = Me.txtLoc.Value
    .Cells(iRow, 4).Value = Me.txtDate.Value
    .Cells(iRow, 5).Value = Me.txtPrice.Value
    End with

    Now i need to update or change some values in DB1 by using another user form. How can the user form find the row of the entry with all the informations which has to be changed?

    Thanx
    det
    Presumably, you have identified the data to be amended in order to load it into the form textboxes. From that point you should have a row number, or some other 'handle' that you should preserve and re-use that when writing back to the DB1.

    AM I on the right lines?

  5. #5
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    The problem is how do i identify the data which is unsorted to load it into the form textboxes?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by det60
    The problem is how do i identify the data which is unsorted to load it into the form textboxes?
    I know, I get that much. But I need some help. I havde no idea what iDB1 looks like, I have no idea how you decide what to load on that second form, etc. etc. You might know, but you are not telling me (yet!).

    I presume that you can create data on form 1 and it gets appended to DB1 okay. SO lets say there are 100 items on DB1, in English, how would you decide which one is to be edited in form2?

  7. #7
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    Sorry for not explaining it properly. But you are right. Like you said there are 100 items in Db1 which means 100 rows and i realize something is wrong in one entry which is somewhere in Db1. How do i get this entry with Partid, Part, etc... into my form2?

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by det60
    Sorry for not explaining it properly. But you are right. Like you said there are 100 items in Db1 which means 100 rows and i realize something is wrong in one entry which is somewhere in Db1. How do i get this entry with Partid, Part, etc... into my form2?
    Seeing as you seem to be doing a visual identification, once identifed, select that row, fire up the form, and use something like


    With wksPartsData
        Me.cboPartid.Value = .Cells(ActiveCell.Row, 1).Value
        Me.cboPart.Value = .Cells(ActiveCell.Row, 2).Value
        Me.txtLoc.Value = .Cells(ActiveCell.Row, 3).Value
        Me.txtDate.Value = .Cells(ActiveCell.Row, 4).Value
        Me.txtPrice.Value = .Cells(ActiveCell.Row, 5).Value
    End With

  9. #9
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    How does this visual identification look like or can you tell me the code to get the right row?

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by det60
    How does this visual identification look like or can you tell me the code to get the right row?
    We are struggling here aren't we?

    The visual identification I am referring to is done by you, so you tell me. You said

    Quote Originally Posted by det60
    and i realize something is wrong in one entry which is somewhere in Db1.
    which I read as you looked at the data and saw (visual) that something was wrong. You then called up a form and you need to get that data onto the form. Somehow, we have to have a way of knowing what row it is, and yous eem to be saying you realize. Well great, but the computer won't know what you realize, it needs some information within the data.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi det, and welcome to VBAX,

    xld's doing his best to help you here but you're not really giving him (or anyone else) much to go on.

    Here's a suggestion, why don't you remove any sensitive data then zip and attach the workbook (use 'manage attachments' when next posting) for us to look at.

    Also, when you do, give as much detail as you can about exactly what you want the code to do and its' eventual outcome.

    Regards,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  12. #12
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    Here comes the whole code for my Input User Form:

    Option Explicit 
     
    Private Sub cmdDel_Click()
    'clear the data
    Me.cboPart.Value = ""
    Me.cboPartid.Value = ""
    Me.txtDate.Value = Format(Date, "Medium Date")
    Me.txtQty.Value = 1
    Me.txtPrice.Value = ""
    Me.txtLoc.Value = ""
    Me.cboPart.SetFocus
    End Sub
     
    Private Sub cmdAdd_Click()
    Dim iRow As Long
    'find first empty row in DB1
    iRow = wksPartsData.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).row
    'check for a part number
    If Trim(Me.cboPart.Value) = "" Then
    Me.cboPart.SetFocus
    MsgBox "Please enter a part number"
    Exit Sub
    End If
    'copy the data to the DB1
    With wksPartsData
    .Cells(iRow, 1).Value = Me.cboPartid.Value
    .Cells(iRow, 2).Value = Me.cboPart.Value
    .Cells(iRow, 4).Value = Me.txtLoc.Value
    .Cells(iRow, 5).Value = Me.txtDate.Value
    .Cells(iRow, 6).Value = Me.txtQty.Value
    .Cells(iRow, 9).Value = Me.txtPrices.Value
    End With
    'copy the data to the LookupList1
    With wksLookupLists
    .Cells(iRow, 1).Value = Me.txtPartID.Value
    .Cells(iRow, 2).Value = Me.cboPart.Value
    End With
    'clear the data
    Me.cboPart.Value = ""
    Me.cboPartid.Value = ""
    Me.txtDate.Value = Format(Date, "Medium Date")
    Me.txtQty.Value = 1
    Me.txtPrice.Value = ""
    Me.txtLoc.Value = ""
    Me.cboPart.SetFocus
    End Sub
     
    Private Sub cmdClose_Click()
    Unload Me
    End Sub
     
    Private Sub UserForm_Initialize()
    Dim cPart As Range
    Dim cPartid As Range
     
    For Each cPartid In wksLookupLists1.Range("PartIDList")
    With Me.cboPartid
    .AddItem cPartid.Value
    .List(.ListCount - 1, 1) = cPartid.Offset(0, 1).Value
    End With
    Next cPartid
    For Each cPart In wksLookupLists1.Range("LocationList")
    With Me.cboPart
    .AddItem cPart.Value
    .List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
    End With
    Next cPart
    Me.txtDate.Value = Format(Date, "Medium Date")
    Me.txtQty.Value = 1
    Me.txtPrice.Value = ""
    Me.txtLoc.Value = ""
    Me.cboPart.SetFocus
    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
    After 100 entries how can i find the row number of a specific cell value in Db1 by a second User Form without searching for it myself in DB1?
    The second User Form should show me PartID, Part, Date, Loc and Price from DB1 as Default in some Text Boxes.

    Thanx
    Det
    Last edited by johnske; 07-12-2005 at 02:17 AM. Reason: to include VBA tags

  13. #13
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    Without being able to see the workbook and how the data is actually laid out, what # of textboxes are on the 2nd form, etc, etc..

    Since it looks like you may have some knowledge of code by what you posted there is a workbook download on this site called "populate userform" or something close to that, download it and look over how it happens, it may help get you pointed in the right direction, but it would be quicker and easier for us to help you out if you could attach the workbook, as recreating your useform from scratch just to try and find out what going wrong for you doesn't sound like a lot of fun.

    Quickest solution, attach a sample.
    Last edited by Justinlabenne; 07-12-2005 at 06:03 AM. Reason: I can't spell..
    Justin Labenne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •