Results 1 to 8 of 8

Thread: submit data in visual basic

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    46

    submit data in visual basic

    hi,
    i have another problem, when a user hits the submit button data is submitted on an excel spreadsheet but its not stopping a user to submit the data only once.

    how can i make my code to work in a way that if a user press submits button it shows a msg box informing user that the data has been submitted.

    I have tried attaching msgbox buts its not working.

  2. #2
    Addicted Member Smartacus's Avatar
    Join Date
    Oct 2009
    Location
    Deep South, USA
    Posts
    196

    Re: submit data in visual basic

    Well you are not telling us a lot.

    1) Does your form save to a single row in the work sheet or to many worksheets?

    2) What if the user did need to save it again because they found a typo? The rule would have to allow for that.

    3) When they press the Submit button is it creating another row?

    Easy way?

    I suppose you could disable the button after pressing it until the next record but again that does leave the user not being able save a change if it takes them more than once to get it right.

    When we do Insert or Updates in a DB we do If Exists, if true we update it, if false we create the record.

    Come back and give more description about your submit button and data rows in your work sheet to get more help or suggestions.
    ***************************************************
    Smartacus comes packaged "As Is With No Warranty"

    ************* Useful Links ******************
    FAQs: Index / Database Development / .NET CodeBank /
    Before Posting Here...MSDN

    MZTools (I love this tool when using VB6 - Free) /

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    46

    Re: submit data in visual basic

    Hi, thanks for the reply,

    1) On pressing Submit button my form saves the results to a single row in the work sheer.

    2) At the minute if a user enters data and press the Submit button it saves the data in the empty row on the worksheet but if I user thinks he has made an error and refills it and again press the submit button, instead of overwriting the submission it saves the data to next empty row.

    This is the code which is attached to submit button.

    Private Sub cmdSubmit_Click()
    ActiveWorkbook.Sheets("sheet1").Activate
    Range("A1").Select
    Do
    If IsEmpty(activecell) = False Then
    activecell.Offset(1, 0).Select
    End If
    Loop Until IsEmpty(activecell) = True


    activecell.Value = txtbox1.Text

    activecell.Offset(0, 1) = cbDataDesc.Value

    If chkBulk.Value Then
    activecell.Offset(0, 2).Value = "B"
    End If

    If chkSensitive = True Then
    activecell.Offset(0, 3).Value = "S"
    End If

    activecell.Offset(0, 4) = cboLocation.Value
    activecell.Offset(0, 5) = txtSource.Value


    ThisWorkbook.Save

    End Sub


    I really apreciate your help.
    Thanks

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: submit data in visual basic

    how do you refill to correct?

    use a form level variable to keep the row number of the filled data
    you can use this to save back to the same row
    if new record set to 0 or next empty row
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    46

    Re: submit data in visual basic

    sorry being thick but i dont understand this.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: submit data in visual basic

    all right add another textbox to your form, can be invisible if you like
    store the row number there
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    46

    Re: submit data in visual basic

    hi, tahnks for the reply, can you please incorportae this in to the code that i have provided here. If i create a text box then what declarations do i have to make? I understand the invisble one but how do i declare it to store the rows?

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: submit data in visual basic

    as i have not seen the code you use to load data to the userform it is hard to show how to get the row number, but change the submit code like
    vb Code:
    1. Private Sub cmdSubmit_Click()
    2. ActiveWorkbook.Sheets("sheet1").Activate
    3. if hiddentext = 0 then hiddentext = range("a65335").end(xlUp).Row +1  ' next empty row
    4. ' if hidden textbox already has a value from when the record was loaded then it will overwrite the existing
    5. cells(hiddentext,1) = txtbox1.Text
    6. cells(hiddentext,2) = cbDataDesc.Value
    7.  
    8. If chkBulk.Value Then
    9. cells(hiddentext,3).Value = "B"
    10. End If
    11.  
    12. If chkSensitive = True Then
    13. cells(hiddentext,4).Value = "S"
    14. End If
    15.  
    16. cells(hiddentext,5) = cboLocation.Value
    17. cells(hiddentext,6) = txtSource.Value
    18. hiddentext = 0
    19. ThisWorkbook.Save
    20. End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width