Command button to save cahnges on the record

cbabi2

Member
Local time
Yesterday, 16:21
Joined
Sep 29, 2014
Messages
34
I have a form named CORRES_TYP with 3 text boxes and a list box. I also have a separate table with 3 field from where the information I put in the form was saved.

In my form whenever I put information on the textbox at hit add record button, these information are saved in my table and will reflect on the listbox on my form below the textboxes. Also if I select a record in the Listbox the record I selected will apprear on the corresponding textbox in the same form.

My problem is that I have been trying to create a command button that will save and change the existing record everytime I select an item in the list box and modify the information through the textbox. Here are some infromation about my table and form:

Table name = CORRES_TYP
Field 1 = CODE (Primary key, No Duplicates)
Field 2 = DESCRIPTION
Field 3 = FOLDER

Form name = CORRES_TYP
Textbox 1 = CODE
Textbox 2 = DESCRIPTION
Textbox 3 = FOLDER
Listbox name = LIST14

I have attach here my database to fully understande my problem. Please bear with my long post for its my 1st time to post something to any forum. Thanks
 

Attachments

quick question: what is the Add Record button supposed to do?

- add a new record or
- update an existing record or
- save the record you've just entered as a new record

And likewise, what should happen when you click refresh?
 
when I hit the add record button, everything I type in the textbox will be added in the record unless the CODE is not the same with the existing record (which is the primary key to my table ) - Its like a new record is added.

Thanks CazB for the quick reply....

When I hit the refresh button, all entries seen on the textbox will disappear. Its like you are deleteing the info shown in the textbox the so you can type a new info (making the textbox blank)...

I forgot to mention, I did this using Access 2003, got through and created evreything just by reading threads on this forum (great help)
 
Your form setup is wrong, you need to use a unbound form and have some VBA code for adding and updating the data.
Database attached.
 

Attachments

Thank you JHB for your reply but I cant still modify record using the databse that you attached..it just added the new record like what I did on the original database..

The original form for me was fine I just need to find a way to modify existing record which was shown on the text box everytime i hit the list box..(ie adding command button)

Please try to work around my original form,
1. add information on the textboxes(with CODE not the same as listed in the textbox - New Entry), hit save button, observe the list box
2. add information on the textboxes, hit refresh, observe the list box
3. tick any entry on the list box, observe textbox, try to change DESCRIPTION and/or FOLDER texbox( do not change the CODE), hit save and see if it will modify the same record on the listbox...(this is where my problem starts)..

Thank you again for your response... :)
 
you should not do that. if the combo box manages a "set of data" - then all you need to store is the value of the combo box you selected.

that is what normalisation is all about.

you can show the details of the combo box in controls if need be
control1 = cbobox.column(1)
control2 = cbobox.column(2)
control3 = cbobox.column(3)
 
Thanks Dave for the reply but I am confused (I am stil a beginner), what is the thing that I should not do? and I dont have combo box in my form. You can check & work around in my form in the attached database if you like. My problem is editing "set of Data" I selected from the list box (reflected from my table and edited though the textboxes...CODE remains the same)....thanks again :)
 

Attachments

Thank you JHB for your reply but I cant still modify record using the databse that you attached..it just added the new record like what I did on the original database..
Hmm - are you sure you press the right button? :)
When you do a selection in the list, edit the value in the textboxes and press "Refresh" the value(s) in the list is/are updated, I've attached a picture showing before and after editing DESCRIPTION and FOLDER.
 

Attachments

  • BeforeAfter.jpg
    BeforeAfter.jpg
    86 KB · Views: 134
Thank you for your help JHB, I finally got the button I want through your help. I examined the VB codes that you changed or added and I found this one which I cant analyze

Private Sub FindInList()
Dim ListValuefound As Boolean, x As Long

For x = 0 To Me.List14.ListCount
If Me.CODE = Me.List14.Column(0, x) And Me.DESCRIPTION = Me.List14.Column(1, x) And Me.FOLDER = Me.List14.Column(2, x) Then
Me.List14.Selected(x) = True
Exit For
End If
Next
End Sub

If its ok with you, can you tell what these codes are for and how they effect the form... Thanks again



ps.

What command symntax should I use if I to make a command button to delete a record I selected on the same listbox?

:):)
 
Last edited:
..
If its ok with you, can you tell what these codes are for and how they effect the form... Thanks again
It select the row in the list, where the values are equal changes you made.
 

Users who are viewing this thread

Back
Top Bottom