Help with tables. (1 Viewer)

GaDauBac

Member
Local time
Tomorrow, 02:55
Joined
Mar 22, 2021
Messages
42
Hi everybody!
I don't know how to move records with field "Luu" = true from database "QCNB" to database "LuuDuLieuQCNB" with the same table. After that, all the fields that have been moved will be deleted. I have attached the folder containing the database here.
Hope everyone can help me.
Thanks everyone!
 

Attachments

  • TestSaveData.zip
    202.6 KB · Views: 259

Gasman

Enthusiastic Amateur
Local time
Today, 19:55
Joined
Sep 21, 2011
Messages
14,047
Link the source table to the new dB.
Run a append query.
Then run a delete query.

Backup both dB first. Make the append query a select query first. To Make sure you have the correct data. Though your criteria is simple, I would still do it that way.
 

onur_can

Active member
Local time
Today, 12:55
Joined
Oct 4, 2015
Messages
180
Working only with the t2_ChiTetHopDong table. I saw that 2 tables are not the same, definitely repeat and the structure of the tables to which you will transfer the data should be one-to-one. Otherwise, you cannot. After providing this, you can run SQL.

SQL:
INSERT INTO tb2_ChiTietHopDong ( SoHD, MaKH, HangMucSP, DVT, ChieuCao, ChieuNgang, ChieuSau, KhoiLuong, SoLuong, DonGia, ThanhTien, ThanhToan, NhanVien, ChucVuNV, GhiChu, Luu ) IN 'C:\Users\AS\Downloads\TestSaveData\TestLuuDuLieu\LuuDuLieuQCNB.accdb'
SELECT tb2_ChiTietHopDong.SoHD, tb2_ChiTietHopDong.MaKH, tb2_ChiTietHopDong.HangMucSP, tb2_ChiTietHopDong.DVT, tb2_ChiTietHopDong.ChieuCao, tb2_ChiTietHopDong.ChieuNgang, tb2_ChiTietHopDong.ChieuSau, tb2_ChiTietHopDong.KhoiLuong, tb2_ChiTietHopDong.SoLuong, tb2_ChiTietHopDong.DonGia, tb2_ChiTietHopDong.ThanhTien, tb2_ChiTietHopDong.ThanhToan, tb2_ChiTietHopDong.NhanVien, tb2_ChiTietHopDong.ChucVuNV, tb2_ChiTietHopDong.GhiChu, tb2_ChiTietHopDong.Luu
FROM tb2_ChiTietHopDong
WHERE (((tb2_ChiTietHopDong.Luu)=True));
 

GaDauBac

Member
Local time
Tomorrow, 02:55
Joined
Mar 22, 2021
Messages
42
Thanks everyone. I did it.
When changing to Office 2007 or later, Access used a library other than 2003, so it had to be explicitly declared as using the DAO or ADODB library.
Do not use "Dim As Database", must use Dim db As DAO.Database -
Dim rs As DAO.Recordset
 

GaDauBac

Member
Local time
Tomorrow, 02:55
Joined
Mar 22, 2021
Messages
42
Thanks everyone. I did it.
When changing to Office 2007 or later, Access used a library other than 2003, so it had to be explicitly declared as using the DAO or ADODB library.
Do not use "Dim As Database", must use Dim db As DAO.Database - Dim rs As DAO.Recordset
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:55
Joined
Sep 21, 2011
Messages
14,047
Thanks everyone. I did it.
When changing to Office 2007 or later, Access used a library other than 2003, so it had to be explicitly declared as using the DAO or ADODB library.
Do not use "Dim As Database", must use Dim db As DAO.Database -
Dim rs As DAO.Recordset
No, I have used just Dim AS Database in the past, until I knew better, and I use 2007.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:55
Joined
Feb 19, 2002
Messages
42,973
The problem is caused because there are several objects that exist in both the DAO and the ADO libraries. Access forms by default are DAO even in the one or possibly two version of Access where MS made ADO the default library. This caused nothing but trouble for lots of people. So it is important to understand that when VBA is looking for the definition of an object, it searches the form module first and then goes through the list of reference libraries. Therefore if the first reference library is DAO, ALL of your ambiguous db objects will be assumed to be DAO but if the ADO library is referenced first, then they will all be assumed to be ADO. The solution is to ALWAYS disambiguate your db objects when you declare them. That way it doesn't matter what library is defined first, by disambiguating the DIM, you are telling VBA where to look. It is also a little like defensive driving. If some stupid programmer, not you, later modifies the app and decides that he loves ADO and therefore insists on adding ADO to your pure DAO app, your existing code will not be adversely affected when he adds the ADO library first.
 

Isaac

Lifelong Learner
Local time
Today, 12:55
Joined
Mar 14, 2017
Messages
8,738
No, I have used just Dim AS Database in the past, until I knew better, and I use 2007.
It all depends on 1) whether either (ado/dao) libraries are checked in ref's, and 2) which are higher and 3) which libraries share similar objects
Kind of a big ugly mixture.

I have only used ADO for sql server connections/executions, and especially in excel.
 

Users who are viewing this thread

Top Bottom