Help with transfering data from Combo Box to Text Box (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 03:11
Joined
Sep 21, 2011
Messages
14,231
Isn't that backwards, according to thread title?
 

indian818

New member
Local time
Today, 09:11
Joined
Mar 30, 2021
Messages
15
check and test
Spending hours and finding out how to overcome the problem, but another one emerges.
I picked a data from Combo box, access asked me Yes/No, I choose Yes then click Save button, it asked me Yes/No again. I can't stop that second time question. This time I'm really stuck.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:11
Joined
May 7, 2009
Messages
19,231
upload your db.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:11
Joined
May 7, 2009
Messages
19,231
test it again. select a combo will immediately save the record so you need to add a "delete" button.
 

Attachments

  • Transfer data combobox2textbox 2.accdb
    1.7 MB · Views: 91

113hans

Member
Local time
Today, 09:11
Joined
Mar 31, 2021
Messages
47
test it again. select a combo will immediately save the record so you need to add a "delete" button.
It's all OK when I choose Yes, it changes to the data I pointed.
But when I choose No, it changes also.
How can I make it work the same way you did to the attached file #18?
 

113hans

Member
Local time
Today, 09:11
Joined
Mar 31, 2021
Messages
47
i tested many times and it is not changing.
Try my move, it's simple:
New record > Give (Mã lưu trữ) any number > Save
Pick from combo box (BỤNG NỮ) > Save
Pick from combo box (THAI 3M) > Save > No
You will see the content of Mota text box stay with (THAI 3M), it doesn't go back to (BỤNG NỮ)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:11
Joined
May 7, 2009
Messages
19,231
check again maybe i uploaded an old version?
 

Attachments

  • Transfer data combobox2textbox 2.accdb
    1.7 MB · Views: 95

113hans

Member
Local time
Today, 09:11
Joined
Mar 31, 2021
Messages
47
No, it's the very version that I make my move. Just give it a try, you'll see.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:11
Joined
May 7, 2009
Messages
19,231
ok test again and make your move same as in post #29
 

Attachments

  • Transfer data combobox2textbox 2.accdb
    1.7 MB · Views: 101

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:11
Joined
Feb 19, 2002
Messages
43,223
If you want to reliably prevent a record from being saved, you need to put your validation code in the form's BeforeUpdate event. Putting the code in any other event might work but will almost certainly leave holes allowing bad/incomplete data from being saved. When a record is saved, the form's BeforeUpdate event is the LAST event to fire before the record is saved. NO MATTER WHAT prompted Access to save the record. If there is an error, you cancel the event and that prevents Access from saving the record.
Code:
If Me.SomeFIeld & "" = "" Then
    Msgbox "Some Field is required.", vbOKOnly
    Me.SomeField.Setfocus
    Cancel = True
    Exit Sub
End If
If Me.SomeDate > Date() Then
    Msgbox "Some Date must be <= Today's date.", vbOKOnly
    Me.SomeDate.SetFocus
    Cancel = True
    Exit Sub
End If
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:11
Joined
Feb 19, 2002
Messages
43,223
Doesn't work for me. You need to do better testing. I end up with mis-matched data.

Please do some reading on database normalization. You should not be copying data from one table to the other, that is the root of the problem. When you choose the option from the combo, ONLY the PK of the referenced record should be saved. You are copying data and that means that the data is in two places AND your code is not copying ALL the fields and that is why you end up with mis matches.

And finally, you have no code in the form's BeforeUpdate event so you will always be able to save partial records. That may be OK but most applications do not find that acceptable.

For your own sanity and that of anyone who must modify the application after you, Always use meaningful names for your controls. Change the control name immediately - BEFORE you add any code to it. Changing the name after the fact, orphans the code so you need to find the code and change the control name there and then go back to the control and click on the event to link the code to the event again.
 

Users who are viewing this thread

Top Bottom