By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,056 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,056 IT Pros & Developers. It's quick & easy.

Adding data to field

100+
P: 250
I have a form and would like with the push of a command button for data to be sent to a comments field based on data entered in a different field. (ex- if field 1 is not "ok" i want the comments field to say "field 1 is not ok") If there is something in the comments field already i dont want it to be replaced with the new data... i want it to be added to it. is this possible? thanks
Jun 15 '12 #1
Share this Question
Share on Google+
1 Reply


beacon
100+
P: 579
The short answer to your question is yes, it is possible.

You will have to add the Click event to your command button. I'm going to assume a couple of things about your form, the fields on it, and the table you're using. Keep in mind that you'll need to change my assumptions to match your naming conventions in your database.

Expand|Select|Wrap|Line Numbers
  1. //Assumptions
  2. Command button name: cmdStatusCheck
  3. Field to check: txtStatus     //This holds the value "Ok" or "Not Ok" - you called this Field1
  4. Comment (text) box: txtComments
  5.  
Now for the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdStatusCheck_Click()
  2.  
  3.      If txtStatus <> "Ok" Then
  4.           If txtComments = "" Then
  5.                txtComments = "Field is not ok"
  6.           Else
  7.                txtComments = txtComments & " " & "Field is not ok"
  8.           End If
  9.      Else
  10.           MsgBox "The field is okay and no comments will be added.", vbInformation + vbOKOnly, "Add Comments"
  11.      End If
  12.  
  13. End Sub
  14.  
Jun 15 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.