|
-
Dec 15th, 2009, 09:03 AM
#1
Thread Starter
Member
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.
-
Dec 15th, 2009, 10:50 AM
#2
Addicted Member
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.
-
Dec 15th, 2009, 02:52 PM
#3
Thread Starter
Member
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
-
Dec 15th, 2009, 03:27 PM
#4
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
-
Dec 15th, 2009, 03:57 PM
#5
Thread Starter
Member
Re: submit data in visual basic
sorry being thick but i dont understand this.
-
Dec 15th, 2009, 09:16 PM
#6
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
-
Dec 16th, 2009, 04:19 AM
#7
Thread Starter
Member
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?
-
Dec 16th, 2009, 06:11 AM
#8
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:
Private Sub cmdSubmit_Click() ActiveWorkbook.Sheets("sheet1").Activate if hiddentext = 0 then hiddentext = range("a65335").end(xlUp).Row +1 ' next empty row ' if hidden textbox already has a value from when the record was loaded then it will overwrite the existing cells(hiddentext,1) = txtbox1.Text cells(hiddentext,2) = cbDataDesc.Value If chkBulk.Value Then cells(hiddentext,3).Value = "B" End If If chkSensitive = True Then cells(hiddentext,4).Value = "S" End If cells(hiddentext,5) = cboLocation.Value cells(hiddentext,6) = txtSource.Value hiddentext = 0 ThisWorkbook.Save 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|