<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[Thủ Thuật Access - Class Moudules]]></title>
		<link>https://thuthuataccess.com/forum/</link>
		<description><![CDATA[Thủ Thuật Access - https://thuthuataccess.com/forum]]></description>
		<pubDate>Tue, 21 Apr 2026 14:53:08 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[danh sách các hàm VBA từ Allenbrowne]]></title>
			<link>https://thuthuataccess.com/forum/thread-12708.html</link>
			<pubDate>Tue, 28 Nov 2023 03:21:30 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=133">btamsgn</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-12708.html</guid>
			<description><![CDATA[Danh sách chỉ mục này liệt kê mã VBA<br />
<a href="http://allenbrowne.com/FuncIndex.html" target="_blank" rel="noopener" class="mycode_url">Microsoft Access tips: VBA Function index (allenbrowne.com)</a>]]></description>
			<content:encoded><![CDATA[Danh sách chỉ mục này liệt kê mã VBA<br />
<a href="http://allenbrowne.com/FuncIndex.html" target="_blank" rel="noopener" class="mycode_url">Microsoft Access tips: VBA Function index (allenbrowne.com)</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Cách chẻ từng câu trong đoạn thêm vào bảng]]></title>
			<link>https://thuthuataccess.com/forum/thread-12583.html</link>
			<pubDate>Mon, 27 Mar 2023 02:45:48 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=133">btamsgn</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-12583.html</guid>
			<description><![CDATA[Chào các bạn,<br />
<br />
Mình có tạo một form gồm : 1 textbox, 1subform và 1 nút lệnh<br />
1. Mình muốn nhận được code cho nút lệnh để chẻ từng câu trong đoạn textbox thành từng câu rồi thêm vào bảng "Tsplit". <br />
2. Hiện tại mình làm bằng tay copy từng câu rồi dán vào bảng.<br />
3. Rất mong nhận được sự trợ giúp từ các bạn.<br />
<br />
Cảm ơn.<br />
Đính kèm: <a href="https://drive.google.com/file/d/10jOrolYyY1a3UuhiynYn_ak17Qg2e5DA/view?usp=share_link" target="_blank" rel="noopener" class="mycode_url">File minh hoa</a>]]></description>
			<content:encoded><![CDATA[Chào các bạn,<br />
<br />
Mình có tạo một form gồm : 1 textbox, 1subform và 1 nút lệnh<br />
1. Mình muốn nhận được code cho nút lệnh để chẻ từng câu trong đoạn textbox thành từng câu rồi thêm vào bảng "Tsplit". <br />
2. Hiện tại mình làm bằng tay copy từng câu rồi dán vào bảng.<br />
3. Rất mong nhận được sự trợ giúp từ các bạn.<br />
<br />
Cảm ơn.<br />
Đính kèm: <a href="https://drive.google.com/file/d/10jOrolYyY1a3UuhiynYn_ak17Qg2e5DA/view?usp=share_link" target="_blank" rel="noopener" class="mycode_url">File minh hoa</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Hiện Form và Module trong file mdb bị ẩn]]></title>
			<link>https://thuthuataccess.com/forum/thread-12278.html</link>
			<pubDate>Wed, 17 Nov 2021 07:13:49 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=21446">mrdieu</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-12278.html</guid>
			<description><![CDATA[Các bạn cho mình hỏi, mình có file database access bị ẩn hết Form và Module mà không biết có cách nào để hiển thị được.<br />
Các bạn có Tool nào có thể mở được giúp mình.<br />
Xin cảm ơn!]]></description>
			<content:encoded><![CDATA[Các bạn cho mình hỏi, mình có file database access bị ẩn hết Form và Module mà không biết có cách nào để hiển thị được.<br />
Các bạn có Tool nào có thể mở được giúp mình.<br />
Xin cảm ơn!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Làm sao kiểm tra những ký tự là chữ hay số]]></title>
			<link>https://thuthuataccess.com/forum/thread-11606.html</link>
			<pubDate>Fri, 31 Jul 2020 01:53:47 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=20060">letnhi</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-11606.html</guid>
			<description><![CDATA[NHờ anh em giúp đỡ. Mình có 1 chuổi ký tự kiểu string, ví dụ "abcd123efg" mình lấy ra  ký tự vị trí số 7 và kiểm tra nó là số hay là chữ. Mục đích mình nếu là sô thì mình đổi ký tự x này thành số này bằng cách dùng hàm CInt(x). Nhưng nếu là chữ thì bỏ qua. <br />
     Vấn đề của mình là không biết làm sao kiểm tra ký tự đó là số hay là chữ. <br />
Mong mọi người giúp đỡ. Chân thành cảm ơn.]]></description>
			<content:encoded><![CDATA[NHờ anh em giúp đỡ. Mình có 1 chuổi ký tự kiểu string, ví dụ "abcd123efg" mình lấy ra  ký tự vị trí số 7 và kiểm tra nó là số hay là chữ. Mục đích mình nếu là sô thì mình đổi ký tự x này thành số này bằng cách dùng hàm CInt(x). Nhưng nếu là chữ thì bỏ qua. <br />
     Vấn đề của mình là không biết làm sao kiểm tra ký tự đó là số hay là chữ. <br />
Mong mọi người giúp đỡ. Chân thành cảm ơn.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Kiểm tra code bằng F8. Không chạy được]]></title>
			<link>https://thuthuataccess.com/forum/thread-11544.html</link>
			<pubDate>Sat, 13 Jun 2020 03:01:30 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=20060">letnhi</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-11544.html</guid>
			<description><![CDATA[Mình làm chường trình thời gian đầu mình đánh dấu kiểm tra code chạy bằng F8 (không biết gọi cái tên gi?) chạy rất tốt. rồi mình làm riết bây giờ nó không chay được, sau khi đánh dấu và nó không chạy nữa và ra kết quả nếu không có lỗi còn nếu có lỗi nó im re. Mình mở phiên bản cũ thì nó chạy F8 được. Nó bị gì vậy xin mọi người giúp đỡ. Cảm ơn nhiều.]]></description>
			<content:encoded><![CDATA[Mình làm chường trình thời gian đầu mình đánh dấu kiểm tra code chạy bằng F8 (không biết gọi cái tên gi?) chạy rất tốt. rồi mình làm riết bây giờ nó không chay được, sau khi đánh dấu và nó không chạy nữa và ra kết quả nếu không có lỗi còn nếu có lỗi nó im re. Mình mở phiên bản cũ thì nó chạy F8 được. Nó bị gì vậy xin mọi người giúp đỡ. Cảm ơn nhiều.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Demo Form nhập liệu với bộ nút lệnh Tiến - Lùi - Nhập - Sửa - Xoá (dùng Class module)]]></title>
			<link>https://thuthuataccess.com/forum/thread-11387.html</link>
			<pubDate>Fri, 11 Jan 2019 11:46:33 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=16696">ongke0711</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-11387.html</guid>
			<description><![CDATA[<a href="https://flic.kr/p/2e4W2qy" target="_blank" rel="noopener" class="mycode_url"><span style="font-family: Georgia;" class="mycode_font"><img src="https://farm5.staticflickr.com/4899/46645820852_8f990e6ed7_o.png" loading="lazy"  alt="[Hình: 46645820852_8f990e6ed7_o.png]" class="mycode_img" /></span></a><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size">Trước đâ</span><span style="font-size: medium;" class="mycode_size">y cũng đã có các bài viết chia sẻ code các nút lệnh Tiến - Lùi - Sửa - Xoá của bác <span style="font-weight: bold;" class="mycode_b"><span style="color: #cc3333;" class="mycode_color">tranthanhan1962</span></span>, </span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><span style="font-weight: bold;" class="mycode_b"><span style="color: #ff3333;" class="mycode_color">XuanThanh</span></span> v.v.. và viết trong Standard module sử dụng rất hiệu quả. </span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size">Link tham khảo: </span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="color: #3333cc;" class="mycode_color"><span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://thuthuataccess.com/forum/post-39513.html#pid39513" target="_blank" rel="noopener" class="mycode_url">http://thuthuataccess.com/forum/post-395...l#pid39513</a></span></span></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="color: #3333cc;" class="mycode_color"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://thuthuataccess.com/forum/thread-8467.html" target="_blank" rel="noopener" class="mycode_url"><span style="font-style: italic;" class="mycode_i">http://thuthuataccess.com/forum/thread-8467.html</span></a></span></span></span></span><br />
<br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size">Lần này tôi chia sẻ với các bạn một <span style="font-weight: bold;" class="mycode_b"><span style="color: #3333cc;" class="mycode_color">Form (Unbound) nhập liệu với các nút lệnh cơ bản</span></span> nhất và đặc biệt là viết trong <span style="color: #333399;" class="mycode_color">Class module</span>. </span></span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="https://flic.kr/p/S1wrJU" target="_blank" rel="noopener" class="mycode_url"><img src="https://farm5.staticflickr.com/4818/32823778348_72049cb973_o.png" loading="lazy"  alt="[Hình: 32823778348_72049cb973_o.png]" class="mycode_img" /></a></span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Tại sao dùng Class module:</span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Cũng giống như standard module là bạn có thể sử dụng (gọi) lại ở bất kỳ form nào mà không cần phải viết lại cho từng form.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Riêng với Class module thì các hàm, thủ tục chỉ khởi chạy khi Form gọi nó và sẽ thoát và <span style="color: #3333cc;" class="mycode_color">giải phóng khỏi bộ nhớ khi Form đóng lại</span>. Do đó ứng dụng chạy sẽ chiếm ít tài nguyên hệ thống hơn là các hàm, thủ tục lưu trong standard module. Khi ứng dụng chạy thì toàn bộ các hàm trong standard module sẽ tự động load hết lên memory.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Dùng Class thì số dòng code viết cho từng Form sẽ được giảm đi rất nhiều.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Đối với các Form với nhiều Control xử lý phức tạp và lặp đi lặp lại nhiều thì dùng Class sẽ hiệu quả hơn (như ví dụ trong bài post trước của tôi về Form với các nút Sort và Filter theo từng Field).</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Thực ra không phải trường hợp nào bạn cũng dùng class. Có những sự kiện đơn giản chỉ cần dùng form module hoặc standard module là đủ xài rồi. Nếu dùng class thì hơi quá, giống như là dùng "Dao mổ bò để giết gà" vậy.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Bạn có thể tham khảo thêm về Class module trong các link sau:</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://thuthuataccess.com/forum/thread-5297.html" target="_blank" rel="noopener" class="mycode_url">http://thuthuataccess.com/forum/thread-5297.html</a></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://www.kallal.ca/Articles/WhyClass.html" target="_blank" rel="noopener" class="mycode_url">http://www.kallal.ca/Articles/WhyClass.html</a></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://www.cpearson.com/excel/classes.aspx" target="_blank" rel="noopener" class="mycode_url">http://www.cpearson.com/excel/classes.aspx</a></span></span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Trở lại Form demo này. Tuy là demo cơ bản nhưng tôi nghĩ nó cũng khá đầy đủ cho một form nhập liệu để các bạn tham khảo. </span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Form bao gồm 11 nút lệnh cơ bản: Thêm - Sửa - Xoá - Huỷ - Tìm kiếm - ...</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Xuất file sang Word (Pdf).</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Có form tìm kiếm theo tuỳ chọn Field.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Bẫy các lỗi nhập liệu.</span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="https://flic.kr/p/2e9J87r" target="_blank" rel="noopener" class="mycode_url"><img src="https://farm8.staticflickr.com/7896/46700081121_4e974abe1d_z.jpg" loading="lazy"  alt="[Hình: 46700081121_4e974abe1d_z.jpg]" class="mycode_img" /></a></span></span><br />
<br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Qui định thiết kế trong Form:</span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Các nút lệnh đặt tên có các ký tự đầu là "btn" -&gt; button. Vd: btnAdd. Bạn không được thay đổi tên (name) các nút lênh vì có liên quan đến code gọi trong class. Nếu muốn đổi thì phải đổi đồng bộ luôn trong class.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Các Textbox dùng để nhập liệu phải đặt thuộc tính Tag=Yes. Mục đích: để code xác định những textbox nào trên form để lấy dữ liệu cũng như gán dữ liệu cho nó. Các textbox này cũng đặt Name trùng với tên Field.</span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Code cho class module: đặt tên <span style="font-weight: bold;" class="mycode_b"><span style="color: #3333cc;" class="mycode_color">clsDataEntry</span></span></span></span><br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">Option&nbsp;Explicit<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mvarButtons</span><span style="color: #007700">(</span><span style="color: #0000BB">11</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">WithEvents&nbsp;mctlForm&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Access</span><span style="color: #007700">.</span><span style="color: #0000BB">Form<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mlblLabelToUpdate&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Access</span><span style="color: #007700">.</span><span style="color: #0000BB">Label<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mlngTotalRecords&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mrstFormRecordset&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">DAO</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrSQL&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mvarBookmark&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Variant<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mctlFocusSave&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mblnAddMode&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mblnEditMode&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mblnDisplayRecordPos&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrSourceTable&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrPrimaryKey&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /><br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">mconBGAddNew&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">13691373&nbsp; &nbsp; </span><span style="color: #DD0000">'RGB(237,&nbsp;233,&nbsp;208)<br />Private&nbsp;Const&nbsp;mconBGSave&nbsp;=&nbsp;16777215<br /><br />Private&nbsp;Sub&nbsp;Class_Initialize()<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Gán&nbsp;các&nbsp;nút&nbsp;lenh&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">Navigation&nbsp;buttons</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">vào&nbsp;</span><span style="color: #007700">Array&nbsp;</span><span style="color: #0000BB">de&nbsp;goi&nbsp;trong&nbsp;hàm&nbsp;</span><span style="color: #DD0000">"processCMD"<br />'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dùng&nbsp;de&nbsp;enabled/disable&nbsp;các&nbsp;nút&nbsp;lenh&nbsp;tuy&nbsp;theo.<br />'&nbsp;</span><span style="color: #0000BB">Chú&nbsp;ý</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB"> &nbsp; Ten&nbsp;các&nbsp;nut&nbsp;lenh&nbsp;trong&nbsp;Form&nbsp;phai&nbsp;dong&nbsp;bo&nbsp;voi&nbsp;code&nbsp;trong&nbsp;</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">này</span><span style="color: #007700">.</span><span style="color: #0000BB">Vd</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">"btnFirst"</span><span style="color: #007700">.<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;So&nbsp;luong&nbsp;các&nbsp;nut&nbsp;lenh&nbsp;cung&nbsp;phai&nbsp;nhat&nbsp;quán.<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /><br /> &nbsp; mvarButtons(0)&nbsp;=&nbsp;"btnFirst"<br /> &nbsp; mvarButtons(1)&nbsp;=&nbsp;"btnPrevious"<br /> &nbsp; mvarButtons(2)&nbsp;=&nbsp;"btnNext"<br /> &nbsp; mvarButtons(3)&nbsp;=&nbsp;"btnLast"<br /> &nbsp; mvarButtons(4)&nbsp;=&nbsp;"btnAdd"<br /> &nbsp; mvarButtons(5)&nbsp;=&nbsp;"btnEdit"<br /> &nbsp; mvarButtons(6)&nbsp;=&nbsp;"btnSave"<br /> &nbsp; mvarButtons(7)&nbsp;=&nbsp;"btnDelete"<br /> &nbsp; mvarButtons(8)&nbsp;=&nbsp;"btnUndo"<br /> &nbsp; mvarButtons(9)&nbsp;=&nbsp;"btnFind"<br /> &nbsp; mvarButtons(10)&nbsp;=&nbsp;"btnExit"<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Class_Initialize",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;Class_Terminate()<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; If&nbsp;Not&nbsp;mrstFormRecordset.EOF&nbsp;Then&nbsp;mrstFormRecordset.Close<br /> &nbsp; Set&nbsp;mrstFormRecordset&nbsp;=&nbsp;Nothing<br /> &nbsp; Set&nbsp;mctlFocusSave&nbsp;=&nbsp;Nothing<br /> &nbsp; Set&nbsp;mctlForm&nbsp;=&nbsp;Nothing<br /> &nbsp; Set&nbsp;mlblLabelToUpdate&nbsp;=&nbsp;Nothing<br /> &nbsp; Erase&nbsp;mvarButtons<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Class_Terminate",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;InitialiseData()<br /><br />'&nbsp;</span><span style="color: #0000BB"> &nbsp;Lay&nbsp;du&nbsp;lieu&nbsp;va&nbsp;hien&nbsp;thi&nbsp;len&nbsp;form<br /></span><span style="color: #DD0000">'<br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;db&nbsp;As&nbsp;DAO.Database<br /><br /> &nbsp; Set&nbsp;db&nbsp;=&nbsp;CurrentDb<br /> &nbsp; Set&nbsp;mrstFormRecordset&nbsp;=&nbsp;db.OpenRecordset(mstrSQL)<br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; If&nbsp;.RecordCount&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;.EOF&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;0<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MoveLast<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;.RecordCount<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MoveFirst<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvarBookmark&nbsp;=&nbsp;.Bookmark&nbsp; '</span><span style="color: #0000BB">Luu&nbsp;vi&nbsp;tri<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;DisplayData<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;With<br /><br /><br /> &nbsp; Call&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">True</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; If&nbsp;mlngTotalRecords&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"0&nbsp;/&nbsp;0"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"1&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Set&nbsp;db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"InitialiseData"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DataEntryOne"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;Function&nbsp;</span><span style="color: #0000BB">KeyAutoIncrement</span><span style="color: #007700">(</span><span style="color: #0000BB">strField</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /><br /></span><span style="color: #DD0000">'&nbsp;Tra&nbsp;ve&nbsp;gia&nbsp;tri&nbsp;True&nbsp;neu&nbsp;Primary&nbsp;Key&nbsp;là&nbsp;AutoNumber.<br />'&nbsp;</span><span style="color: #0000BB">Dung&nbsp;de&nbsp;thiet&nbsp;lap&nbsp;cac&nbsp;thuoc&nbsp;tinh&nbsp;riêng&nbsp;cho&nbsp;Field&nbsp;này&nbsp;trong&nbsp;Form</span><span style="color: #007700">.</span><span style="color: #0000BB">Vd</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Enabled</span><span style="color: #007700">:</span><span style="color: #0000BB">No</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Background</span><span style="color: #007700">...<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; If&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields</span><span style="color: #007700">(</span><span style="color: #0000BB">strField</span><span style="color: #007700">).</span><span style="color: #0000BB">Attributes&nbsp;</span><span style="color: #007700">And&nbsp;</span><span style="color: #0000BB">dbAutoIncrField</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; KeyAutoIncrement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; KeyAutoIncrement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Exit&nbsp;</span><span style="color: #007700">Function<br /><br /></span><span style="color: #0000BB">HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"KeyAutoIncrement"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;</span><span style="color: #007700">Function<br /><br />Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">blnVal&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean</span><span style="color: #007700">)<br /><br /></span><span style="color: #DD0000">'&nbsp;Muc&nbsp;dich:&nbsp; Locked/&nbsp;Unlocked&nbsp;các&nbsp;textbox&nbsp;nhap&nbsp;lieu<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;fld&nbsp;As&nbsp;Field<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; Dim&nbsp;strControlName&nbsp;As&nbsp;Variant<br /><br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset.Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;=&nbsp;mctlForm.Controls(fld.Name)<br /> &nbsp; &nbsp; &nbsp; If&nbsp;ctl.Tag&nbsp;=&nbsp;"yes"&nbsp;Then&nbsp; &nbsp; '</span><span style="color: #0000BB">Phai&nbsp;thiet&nbsp;lap&nbsp;Tag</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Yes&nbsp;cho&nbsp;các&nbsp;textbox&nbsp;dùng&nbsp;nhap&nbsp;lieu</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Bo&nbsp;qua&nbsp;Field&nbsp;Primary&nbsp;key&nbsp;neu&nbsp;nó&nbsp;là&nbsp;Autonumber<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Not&nbsp;KeyAutoIncrement(fld.Name)&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl.Locked&nbsp;=&nbsp;blnVal<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Next&nbsp;fld<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"ToggleControls",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Public&nbsp;Property&nbsp;Set&nbsp;LabelToUpdate(ByVal&nbsp;lblVal&nbsp;As&nbsp;Label)<br />'&nbsp;</span><span style="color: #0000BB"> Khai&nbsp;bao&nbsp;doi&nbsp;tuong&nbsp;label&nbsp;nào&nbsp;dùng&nbsp;de&nbsp;hien&nbsp;thi&nbsp;thong&nbsp;tin&nbsp;record&nbsp;navigation<br /> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Set&nbsp;mlblLabelToUpdate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">lblVal<br /> &nbsp; <br /> &nbsp; Exit&nbsp;Property<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Set&nbsp;LabelToUpdate"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #0000BB">strMsg&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /><br /></span><span style="color: #DD0000">'&nbsp; Cap&nbsp;nhat&nbsp;noi&nbsp;dung&nbsp;lable&nbsp;hien&nbsp;trang&nbsp;record<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; If&nbsp;mblnDisplayRecordPos&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; mlblLabelToUpdate.Caption&nbsp;=&nbsp;strMsg<br /> &nbsp; End&nbsp;If<br /> &nbsp; Exit&nbsp;Sub<br /> &nbsp; <br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"UpdateLabel",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Public&nbsp;Sub&nbsp;ProcessCMD(intIndex&nbsp;As&nbsp;Integer)<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Duoc&nbsp;goi&nbsp;cho&nbsp;moi&nbsp;nút&nbsp;lenh&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">Them</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Xoa</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">tien</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">lùi</span><span style="color: #007700">...).<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;indx:&nbsp;Tham&nbsp;so&nbsp;xác&nbsp;dinh&nbsp;nút&nbsp;nào&nbsp;duoc&nbsp;bam.<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Select&nbsp;Case&nbsp;intIndex<br /> &nbsp; Case&nbsp;0&nbsp; '</span><span style="color: #0000BB">First<br /> &nbsp; &nbsp; &nbsp; mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">MoveFirst<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay</span><span style="color: #007700">(</span><span style="color: #DD0000">"1&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; <br /> &nbsp; Case&nbsp;1&nbsp; </span><span style="color: #DD0000">'Previous<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MovePrevious<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay(.AbsolutePosition&nbsp;+&nbsp;1&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; <br /> &nbsp; Case&nbsp;2&nbsp; '</span><span style="color: #0000BB">Next<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">MoveNext<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay</span><span style="color: #007700">(.</span><span style="color: #0000BB">AbsolutePosition&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; <br /> &nbsp; Case&nbsp;3&nbsp; </span><span style="color: #DD0000">'Last<br /> &nbsp; &nbsp; &nbsp; mrstFormRecordset.MoveLast<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay(mlngTotalRecords&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; <br /> &nbsp; Case&nbsp;4&nbsp; '</span><span style="color: #0000BB">AddNew<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">False</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB"> &nbsp; </span><span style="color: #DD0000">'&nbsp;unlock&nbsp;tat&nbsp;ca&nbsp;textbox&nbsp;nhap&nbsp;lieu<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;FormatControls(mconBGAddNew)&nbsp; '</span><span style="color: #0000BB">Dinh&nbsp;dang&nbsp;background&nbsp;textbox&nbsp;nhap&nbsp;lieu&nbsp;khi&nbsp;them&nbsp;moi<br /> &nbsp; &nbsp; &nbsp; mblnAddMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mlngTotalRecords&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Luu&nbsp;vi&nbsp;tri&nbsp;record&nbsp;truoc&nbsp;khi&nbsp;AddNew.&nbsp;Neu&nbsp;Undo&nbsp;thi&nbsp;se&nbsp;tra&nbsp;vè&nbsp;vi&nbsp;tri&nbsp;cu.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvarBookmark&nbsp;=&nbsp;mrstFormRecordset.Bookmark<br /> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvarBookmark&nbsp;=&nbsp;""<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel("Dòng&nbsp;m"&nbsp;&amp;&nbsp;ChrW(7899)&nbsp;&amp;&nbsp;"i")<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ClearData<br /> &nbsp; <br /> &nbsp; Case&nbsp;5&nbsp; '</span><span style="color: #0000BB">Edit<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'.LockEdits&nbsp;=&nbsp;True&nbsp; '&nbsp;</span><span style="color: #0000BB">Neu&nbsp;trong&nbsp;moi&nbsp;truong&nbsp;da&nbsp;nguoi&nbsp;dung&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">multi&nbsp;users</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">thì&nbsp;dùng&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">LockEdits&nbsp;de&nbsp;bay&nbsp;loi&nbsp;Edit<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">False</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; mblnEditMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;FormatControls</span><span style="color: #007700">(</span><span style="color: #0000BB">mconBGAddNew</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; <br /> &nbsp; Case&nbsp;6&nbsp; </span><span style="color: #DD0000">'Save<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ToggleControls(True)<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mblnAddMode&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;AddNewRecord<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;mlngTotalRecords&nbsp;+&nbsp;1<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel(mlngTotalRecords&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;mblnEditMode&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EditRecord<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;FormatControls(mconBGSave)<br /> &nbsp; &nbsp; &nbsp; mblnAddMode&nbsp;=&nbsp;False<br /> &nbsp; &nbsp; &nbsp; mblnEditMode&nbsp;=&nbsp;False<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; <br /> &nbsp; Case&nbsp;7&nbsp; '</span><span style="color: #0000BB">Delete<br /> &nbsp; &nbsp; &nbsp; If&nbsp;MsgBoxUni</span><span style="color: #007700">(</span><span style="color: #DD0000">"B"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7841</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;mu"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7889</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;xóa&nbsp;dòng&nbsp;này?"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vbYesNo</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Xác&nbsp;nh"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7853</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;xóa&nbsp;dòng"</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">vbYes&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;DeleteRecord<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; <br /> &nbsp; Case&nbsp;8&nbsp; </span><span style="color: #DD0000">'Undo<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UndoEdit<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; <br /> &nbsp; '</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">9&nbsp; </span><span style="color: #DD0000">'Find<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Thiet&nbsp;lap&nbsp;rieng&nbsp;frmFind&nbsp;tùy&nbsp;tung&nbsp;form<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; Case&nbsp;10&nbsp; </span><span style="color: #DD0000">'Exit<br /> &nbsp; &nbsp; &nbsp; DoCmd.Close&nbsp;acForm,&nbsp;mctlForm.Name<br /> &nbsp; End&nbsp;Select<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"ProcessCMD",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Public&nbsp;Sub&nbsp;GotoRecord(pkey&nbsp;As&nbsp;Variant)<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Di&nbsp;chuyen&nbsp;toi&nbsp;record&nbsp;chi&nbsp;dinh</span><span style="color: #007700">.&nbsp;(</span><span style="color: #0000BB">Standard&nbsp;Search</span><span style="color: #007700">)<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; pkey:&nbsp;Primary&nbsp;key&nbsp;value<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; .FindFirst&nbsp;mstrPrimaryKey&nbsp;&amp;&nbsp;"="&nbsp;&amp;&nbsp;pkey<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay(.AbsolutePosition&nbsp;+&nbsp;1&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; End&nbsp;With<br /> &nbsp; Exit&nbsp;Sub<br /> &nbsp; <br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"GoToRecord",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;ProcessDisplay(strMsg&nbsp;As&nbsp;String)<br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Call&nbsp;DisplayData<br /> &nbsp; Call&nbsp;UpdateLabel(strMsg)<br /> &nbsp; Call&nbsp;UpdateButtonsState&nbsp; '</span><span style="color: #0000BB">Phai&nbsp;setfocus&nbsp;vào&nbsp;control&nbsp;khac&nbsp;truoc&nbsp;khi&nbsp;en</span><span style="color: #007700">/</span><span style="color: #0000BB">disable<br /> &nbsp; Exit&nbsp;Sub<br /> &nbsp; <br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ProcessDisplay"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;UndoEdit</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Dùng&nbsp;Unbound&nbsp;form&nbsp;nen&nbsp;chi&nbsp;can&nbsp;tra&nbsp;vè&nbsp;hien&nbsp;trang&nbsp;cu,&nbsp;chua&nbsp;luu&nbsp;du&nbsp;lieu&nbsp;vao&nbsp;table<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /><br /> &nbsp; Call&nbsp;ToggleControls(True)<br /> &nbsp; Call&nbsp;FormatControls(mconBGSave)<br /> &nbsp; If&nbsp;mlngTotalRecords&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mblnAddMode&nbsp;Then&nbsp; &nbsp; '&nbsp;</span><span style="color: #0000BB">Tra&nbsp;ve&nbsp;vi&nbsp;tri&nbsp;record&nbsp;cu&nbsp;truoc&nbsp;khi&nbsp;AddNew<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Bookmark&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarBookmark<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">AbsolutePosition&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Call&nbsp;DisplayData<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ClearData<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"0&nbsp;/&nbsp;0"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; mblnAddMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False<br /> &nbsp; mblnEditMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UndoEdit"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;AddNewRecord</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Luu&nbsp;record&nbsp;moi&nbsp;vao&nbsp;table<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; Dim&nbsp;fld&nbsp;As&nbsp;DAO.Field<br /> &nbsp; Dim&nbsp;varField&nbsp;As&nbsp;Variant<br /> &nbsp; Dim&nbsp;indx&nbsp;As&nbsp;Integer<br /><br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; .AddNew<br /> &nbsp; &nbsp; &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset.Fields<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;=&nbsp;mctlForm.Controls(fld.Name)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;ctl.Tag&nbsp;=&nbsp;"yes"&nbsp;Then&nbsp; &nbsp; '</span><span style="color: #0000BB">Chi&nbsp;cap&nbsp;nhat&nbsp;du&nbsp;lieu&nbsp;tu&nbsp;textbox&nbsp;có&nbsp;Tag</span><span style="color: #007700">=</span><span style="color: #0000BB">yes<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varField&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;KeyAutoIncrement</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;=&nbsp;.</span><span style="color: #0000BB">Fields</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Chuyen&nbsp;textbox&nbsp;co&nbsp;zero&nbsp;length&nbsp;thành&nbsp;Null&nbsp;neu&nbsp;can<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mrstFormRecordset(fld.Name)&nbsp;=&nbsp;IIf(varField&nbsp;=&nbsp;"",&nbsp;Null,&nbsp;varField)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; Next&nbsp;fld<br /><br /> &nbsp; &nbsp; &nbsp; .Update<br /> &nbsp; &nbsp; &nbsp; .MoveLast&nbsp; &nbsp; '</span><span style="color: #0000BB">Di&nbsp;chuyen&nbsp;den&nbsp;record&nbsp;vua&nbsp;moi&nbsp;them<br /> &nbsp; End&nbsp;With<br /><br /> &nbsp; RequerySubform<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"AddNewRecord"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;EditRecord</span><span style="color: #007700">()<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /> &nbsp; Dim&nbsp;fld&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Field<br /> &nbsp; Dim&nbsp;varField&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Variant<br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">Edit<br /> &nbsp; &nbsp; &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Tag&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"yes"&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Not&nbsp;KeyAutoIncrement</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varField&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TriM</span><span style="color: #007700">&#36;(</span><span style="color: #0000BB">Nz</span><span style="color: #007700">(</span><span style="color: #0000BB">ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value</span><span style="color: #007700">))<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varField&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">IIf</span><span style="color: #007700">(</span><span style="color: #0000BB">Len</span><span style="color: #007700">(</span><span style="color: #0000BB">varField</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">varField</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">varField<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Next&nbsp;fld<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">Update<br /> &nbsp; End&nbsp;With<br /><br /> &nbsp; RequerySubform<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EditRecord"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;DeleteRecord</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Dùng&nbsp;phuong&nbsp;thuc&nbsp;.Delete&nbsp;cua&nbsp;DAO&nbsp;Recordset.<br />'&nbsp;</span><span style="color: #0000BB"> Chi&nbsp;dùng&nbsp;duoc&nbsp;cho&nbsp;Recordset&nbsp;dang&nbsp;Dynaset</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">khong&nbsp;duoc&nbsp;cho&nbsp;Snapshot<br /></span><span style="color: #DD0000">'&nbsp; DAO&nbsp;Recordset&nbsp;tu&nbsp;dong&nbsp;Delete&nbsp;ma&nbsp;khong&nbsp;thong&nbsp;bao.&nbsp;Nó&nbsp;khong&nbsp;tu&nbsp;dong&nbsp;di&nbsp;chuyen&nbsp;qua&nbsp;record&nbsp;tiep&nbsp;nên&nbsp;phai&nbsp;.MoveNext<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;lngAbsolutePosition&nbsp;As&nbsp;Long<br /><br /><br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; lngAbsolutePosition&nbsp;=&nbsp;.AbsolutePosition<br /> &nbsp; &nbsp; &nbsp; .Delete<br /> &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;mlngTotalRecords&nbsp;-&nbsp;1<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mlngTotalRecords&nbsp;=&nbsp;0&nbsp;Then&nbsp; &nbsp; '</span><span style="color: #0000BB">Vua&nbsp;Xoa&nbsp;record&nbsp;cuôi&nbsp;cùng&nbsp;cua&nbsp;recordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;ClearData<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"0&nbsp;/&nbsp;0"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;lngAbsolutePosition&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mlngTotalRecords&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'Là&nbsp;dong&nbsp;cuoi&nbsp;cùng<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MovePrevious<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lngAbsolutePosition&nbsp;=&nbsp;lngAbsolutePosition&nbsp;+&nbsp;1<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MoveNext<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;DisplayData<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel(lngAbsolutePosition&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; End&nbsp;With<br /><br /> &nbsp; Call&nbsp;RequerySubform<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; If&nbsp;Err.Number&nbsp;=&nbsp;3200&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; MsgBoxUni&nbsp;"B"&nbsp;&amp;&nbsp;ChrW(7841)&nbsp;&amp;&nbsp;"n&nbsp;không&nbsp;th"&nbsp;&amp;&nbsp;ChrW(7875)&nbsp;&amp;&nbsp;"&nbsp;xóa&nbsp;dòng&nbsp;này!"&nbsp;&amp;&nbsp;vbCrLf&nbsp;&amp;&nbsp;ChrW(272)&nbsp;&amp;&nbsp;"ã&nbsp;có&nbsp;d"&nbsp;&amp;&nbsp;ChrW(7919)&nbsp;&amp;&nbsp;"&nbsp;li"&nbsp;&amp;&nbsp;ChrW(7879)&nbsp;&amp;&nbsp;"u&nbsp;phát&nbsp;sinh&nbsp;liên&nbsp;quan.",&nbsp;vbExclamation,&nbsp;"C"&nbsp;&amp;&nbsp;ChrW(7843)&nbsp;&amp;&nbsp;"nh&nbsp;báo."<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"DeleteRecord",&nbsp;"clsDataEntry")<br /> &nbsp; End&nbsp;If<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;DisplayData()<br /><br />'&nbsp;</span><span style="color: #0000BB">Hien&nbsp;thi&nbsp;Record&nbsp;hien&nbsp;tai&nbsp;len&nbsp;Form</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /> &nbsp; Dim&nbsp;fld&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Field<br /> &nbsp; Dim&nbsp;indx&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Integer<br /><br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; If&nbsp;ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Tag&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"yes"&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">).</span><span style="color: #0000BB">Type&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dbDate&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Format</span><span style="color: #007700">(</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"dd/mm/yyyy"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Next&nbsp;fld<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DisplayData"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;ClearData</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Xoa&nbsp;noi&nbsp;dung&nbsp;textbox<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; Dim&nbsp;fld&nbsp;As&nbsp;Field<br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset.Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;=&nbsp;mctlForm.Controls(fld.Name)<br /> &nbsp; &nbsp; &nbsp; If&nbsp;ctl.Tag&nbsp;=&nbsp;"yes"&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl.Value&nbsp;=&nbsp;""<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Next&nbsp;fld<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"ClearData",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;RequerySubform()<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; For&nbsp;Each&nbsp;ctl&nbsp;In&nbsp;mctlForm.Controls<br /> &nbsp; &nbsp; &nbsp; If&nbsp;ctl.ControlType&nbsp;=&nbsp;acSubform&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl.Requery<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Next&nbsp;ctl<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;FormatControls(lngColor&nbsp;As&nbsp;Long)<br /><br />'&nbsp;</span><span style="color: #0000BB"> &nbsp;Dinh&nbsp;dang&nbsp;background&nbsp;cua&nbsp;các&nbsp;textnhap&nbsp;lieu</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">màu&nbsp;vàng&nbsp;khi&nbsp;thêm&nbsp;mói</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">tra&nbsp;vè&nbsp;nhu&nbsp;cu&nbsp;khi&nbsp;Save</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /> &nbsp; Dim&nbsp;fld&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Field<br /><br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; With&nbsp;ctl<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">Tag&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"yes"&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'&nbsp;Bo&nbsp;qua&nbsp;Field&nbsp;Autonumber<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Not&nbsp;KeyAutoIncrement(fld.Name)&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .BackColor&nbsp;=&nbsp;lngColor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; Next&nbsp;fld<br /> &nbsp; DoEvents<br /><br />FormatControls_Exit:<br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"FormatControls",&nbsp;"clsDataEntry")<br /> &nbsp; Resume&nbsp;FormatControls_Exit<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;UpdateButtonsState()<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Enabled</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">Disabled&nbsp;các&nbsp;nút&nbsp;lenh&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">Thêm</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Xóa</span><span style="color: #007700">...)<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1=Enabled;&nbsp;0=Disabled.<br />'&nbsp;</span><span style="color: #0000BB">Gán&nbsp;hàng&nbsp;loat&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">11&nbsp;nút&nbsp;lenh</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">dua&nbsp;theo&nbsp;chuoi&nbsp;11&nbsp;ký&nbsp;tu&nbsp;0&nbsp;1&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">strButtonState</span><span style="color: #007700">).<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mctlFocusSave</span><span style="color: #007700">.</span><span style="color: #0000BB">SetFocus<br /> &nbsp; If&nbsp;mblnAddMode&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'Thêm&nbsp;record&nbsp;moi<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00000010100")&nbsp; '</span><span style="color: #0000BB">Vd</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Enable&nbsp;nút&nbsp;Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Huy&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">index&nbsp;6</span><span style="color: #007700">,</span><span style="color: #0000BB">8&nbsp;</span><span style="color: #007700">=</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; ElseIf&nbsp;mblnEditMode&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'Sua&nbsp;record<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00000010100")<br /> &nbsp; Else&nbsp; &nbsp; '</span><span style="color: #0000BB">Hien&nbsp;trang&nbsp;binh&nbsp;thuong<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">mlngTotalRecords&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons</span><span style="color: #007700">(</span><span style="color: #DD0000">"00001000001"</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB"> &nbsp;</span><span style="color: #DD0000">'Enable&nbsp;nút&nbsp;Them,&nbsp;Dóng<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElseIf&nbsp;mlngTotalRecords&nbsp;=&nbsp;1&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00001101001")&nbsp; &nbsp;'</span><span style="color: #0000BB">Them</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Xoa<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElseIf&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">AbsolutePosition&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'dang&nbsp;o&nbsp;record&nbsp;dau&nbsp;tien<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00111101011")<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElseIf&nbsp;(.AbsolutePosition&nbsp;=&nbsp;mlngTotalRecords&nbsp;-&nbsp;1)&nbsp;Then&nbsp; &nbsp; '&nbsp;</span><span style="color: #0000BB">dang&nbsp;o&nbsp;record&nbsp;cuoi<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons</span><span style="color: #007700">(</span><span style="color: #DD0000">"11001101011"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons</span><span style="color: #007700">(</span><span style="color: #DD0000">"11111101011"</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB"> </span><span style="color: #DD0000">'&nbsp;dang&nbsp;o&nbsp;các&nbsp;record&nbsp;giua<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; End&nbsp;If<br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"UpdateButtonsState",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;EnableDisableButtons(strButtonState&nbsp;As&nbsp;String)<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB"> &nbsp;Enable</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">Disable&nbsp;hàng&nbsp;loat&nbsp;</span><span style="color: #007700">Array&nbsp;(</span><span style="color: #0000BB">11&nbsp;nút&nbsp;lenh</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">dua&nbsp;theo&nbsp;chuoi&nbsp;11&nbsp;ký&nbsp;tu&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;(</span><span style="color: #0000BB">strButtonState</span><span style="color: #007700">).<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1=enabled;&nbsp;0=disabled<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;intindx&nbsp;As&nbsp;Integer<br /> &nbsp; Dim&nbsp;intButtonLength&nbsp;As&nbsp;Integer<br /> &nbsp; Dim&nbsp;strEnabled&nbsp;As&nbsp;String<br /><br /> &nbsp; strButtonState&nbsp;=&nbsp;TriM&#36;(strButtonState)<br /> &nbsp; intButtonLength&nbsp;=&nbsp;Len(strButtonState)<br /> &nbsp; For&nbsp;intindx&nbsp;=&nbsp;1&nbsp;To&nbsp;intButtonLength<br /> &nbsp; &nbsp; &nbsp; strEnabled&nbsp;=&nbsp;Mid&#36;(strButtonState,&nbsp;intindx,&nbsp;1)<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mctlForm.Controls(mvarButtons(intindx&nbsp;-&nbsp;1))<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;.Enabled&nbsp;&lt;&gt;&nbsp;(strEnabled&nbsp;=&nbsp;"1")&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Enabled&nbsp;=&nbsp;(strEnabled&nbsp;=&nbsp;"1")<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; Next&nbsp;intindx<br /> &nbsp; DoEvents<br /><br />EnableDisableButtons_Exit:<br /> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"EnableDisableButtons",&nbsp;"clsDataEntry")<br /> &nbsp; Resume&nbsp;EnableDisableButtons_Exit<br />End&nbsp;Sub<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;FormRecordsetSQL(ByVal&nbsp;sSQL&nbsp;As&nbsp;String)<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; mstrSQL&nbsp;=&nbsp;sSQL&nbsp; &nbsp; '&nbsp;</span><span style="color: #0000BB">Truyen&nbsp;cau&nbsp;lenh&nbsp;SQL&nbsp;làm&nbsp;Form&nbsp;Recordset<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;FormRecordsetSQL"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Set&nbsp;FocusControl</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;cValue&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control</span><span style="color: #007700">)<br /></span><span style="color: #DD0000">'&nbsp;Khi&nbsp;thiet&nbsp;lap&nbsp;Disable&nbsp;control&nbsp;bat&nbsp;buoc&nbsp;phai&nbsp;focus&nbsp;vào&nbsp;1&nbsp;control&nbsp;khác&nbsp;nó.<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Set&nbsp;mctlFocusSave&nbsp;=&nbsp;cValue<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Property&nbsp;Set&nbsp;FocusControl",&nbsp;"clsDataEntry")<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;SourceTable(ByVal&nbsp;sSourceTableName&nbsp;As&nbsp;String)<br />'&nbsp;</span><span style="color: #0000BB"> Gan&nbsp;thuoc&nbsp;tinh&nbsp;nay&nbsp;de&nbsp;du&nbsp;phong</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">Chua&nbsp;dùng&nbsp;den&nbsp;trong&nbsp;</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">này</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mstrSourceTable&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sSourceTableName<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;SourceTable"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;SourceTableName</span><span style="color: #007700">()<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; SourceTableName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mstrSourceTable<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Get&nbsp;SourceTable"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;DisplayRecordPosition</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;blnShowHide&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean</span><span style="color: #007700">)<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mblnDisplayRecordPos&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">blnShowHide<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;DisplayRecordPosition"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;PrimaryKey</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;sPKFieldName&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mstrPrimaryKey&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sPKFieldName<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;PrimaryKey"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Set&nbsp;FormCtl</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;frmVal&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Access</span><span style="color: #007700">.</span><span style="color: #0000BB">Form</span><span style="color: #007700">)<br /></span><span style="color: #DD0000">'frmVal:&nbsp;Gan&nbsp;Form&nbsp;chua&nbsp;cac&nbsp;NavButton&nbsp;xu&nbsp;ly&nbsp;cho&nbsp;class<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Set&nbsp;mctlForm&nbsp;=&nbsp;frmVal<br /> &nbsp; Call&nbsp;InitialiseData<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Property&nbsp;Set&nbsp;FormCtl",&nbsp;"clsDataEntry")<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Code cho Form thì chỉ cần khởi tạo class ở sự kiện Form_Open là các nút lệnh có thể chạy: tham khảo thêm trong file.</span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="https://flic.kr/p/S1DWk7" target="_blank" rel="noopener" class="mycode_url"><img src="https://farm5.staticflickr.com/4826/32825240308_22ac954636_c.jpg" loading="lazy"  alt="[Hình: 32825240308_22ac954636_c.jpg]" class="mycode_img" /></a></span></span><br />
<br />
<br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Link demo: <a href="http://www.mediafire.com/file/rzynj8tcera43e3/DataEntry_NavigationButtons_Class.rar/file" target="_blank" rel="noopener" class="mycode_url">http://www</a></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="http://www.mediafire.com/file/rzynj8tcera43e3/DataEntry_NavigationButtons_Class.rar/file" target="_blank" rel="noopener" class="mycode_url">.mediafire.com/file/rzynj8tcera43e3/DataEntry_NavigationButtons_Class.rar/file</a></span></span><br />
<br />
<br />
<img src="https://i.imgur.com/0buuZ3A.gif" loading="lazy"  alt="[Hình: 0buuZ3A.gif]" class="mycode_img" />]]></description>
			<content:encoded><![CDATA[<a href="https://flic.kr/p/2e4W2qy" target="_blank" rel="noopener" class="mycode_url"><span style="font-family: Georgia;" class="mycode_font"><img src="https://farm5.staticflickr.com/4899/46645820852_8f990e6ed7_o.png" loading="lazy"  alt="[Hình: 46645820852_8f990e6ed7_o.png]" class="mycode_img" /></span></a><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size">Trước đâ</span><span style="font-size: medium;" class="mycode_size">y cũng đã có các bài viết chia sẻ code các nút lệnh Tiến - Lùi - Sửa - Xoá của bác <span style="font-weight: bold;" class="mycode_b"><span style="color: #cc3333;" class="mycode_color">tranthanhan1962</span></span>, </span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><span style="font-weight: bold;" class="mycode_b"><span style="color: #ff3333;" class="mycode_color">XuanThanh</span></span> v.v.. và viết trong Standard module sử dụng rất hiệu quả. </span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size">Link tham khảo: </span></span></span><br />
<span style="font-style: italic;" class="mycode_i"><span style="color: #3333cc;" class="mycode_color"><span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://thuthuataccess.com/forum/post-39513.html#pid39513" target="_blank" rel="noopener" class="mycode_url">http://thuthuataccess.com/forum/post-395...l#pid39513</a></span></span></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="color: #3333cc;" class="mycode_color"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://thuthuataccess.com/forum/thread-8467.html" target="_blank" rel="noopener" class="mycode_url"><span style="font-style: italic;" class="mycode_i">http://thuthuataccess.com/forum/thread-8467.html</span></a></span></span></span></span><br />
<br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size">Lần này tôi chia sẻ với các bạn một <span style="font-weight: bold;" class="mycode_b"><span style="color: #3333cc;" class="mycode_color">Form (Unbound) nhập liệu với các nút lệnh cơ bản</span></span> nhất và đặc biệt là viết trong <span style="color: #333399;" class="mycode_color">Class module</span>. </span></span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="https://flic.kr/p/S1wrJU" target="_blank" rel="noopener" class="mycode_url"><img src="https://farm5.staticflickr.com/4818/32823778348_72049cb973_o.png" loading="lazy"  alt="[Hình: 32823778348_72049cb973_o.png]" class="mycode_img" /></a></span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Tại sao dùng Class module:</span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Cũng giống như standard module là bạn có thể sử dụng (gọi) lại ở bất kỳ form nào mà không cần phải viết lại cho từng form.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Riêng với Class module thì các hàm, thủ tục chỉ khởi chạy khi Form gọi nó và sẽ thoát và <span style="color: #3333cc;" class="mycode_color">giải phóng khỏi bộ nhớ khi Form đóng lại</span>. Do đó ứng dụng chạy sẽ chiếm ít tài nguyên hệ thống hơn là các hàm, thủ tục lưu trong standard module. Khi ứng dụng chạy thì toàn bộ các hàm trong standard module sẽ tự động load hết lên memory.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Dùng Class thì số dòng code viết cho từng Form sẽ được giảm đi rất nhiều.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Đối với các Form với nhiều Control xử lý phức tạp và lặp đi lặp lại nhiều thì dùng Class sẽ hiệu quả hơn (như ví dụ trong bài post trước của tôi về Form với các nút Sort và Filter theo từng Field).</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Thực ra không phải trường hợp nào bạn cũng dùng class. Có những sự kiện đơn giản chỉ cần dùng form module hoặc standard module là đủ xài rồi. Nếu dùng class thì hơi quá, giống như là dùng "Dao mổ bò để giết gà" vậy.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Bạn có thể tham khảo thêm về Class module trong các link sau:</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://thuthuataccess.com/forum/thread-5297.html" target="_blank" rel="noopener" class="mycode_url">http://thuthuataccess.com/forum/thread-5297.html</a></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://www.kallal.ca/Articles/WhyClass.html" target="_blank" rel="noopener" class="mycode_url">http://www.kallal.ca/Articles/WhyClass.html</a></span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-size: medium;" class="mycode_size"><a href="http://www.cpearson.com/excel/classes.aspx" target="_blank" rel="noopener" class="mycode_url">http://www.cpearson.com/excel/classes.aspx</a></span></span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Trở lại Form demo này. Tuy là demo cơ bản nhưng tôi nghĩ nó cũng khá đầy đủ cho một form nhập liệu để các bạn tham khảo. </span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Form bao gồm 11 nút lệnh cơ bản: Thêm - Sửa - Xoá - Huỷ - Tìm kiếm - ...</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Xuất file sang Word (Pdf).</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Có form tìm kiếm theo tuỳ chọn Field.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Bẫy các lỗi nhập liệu.</span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="https://flic.kr/p/2e9J87r" target="_blank" rel="noopener" class="mycode_url"><img src="https://farm8.staticflickr.com/7896/46700081121_4e974abe1d_z.jpg" loading="lazy"  alt="[Hình: 46700081121_4e974abe1d_z.jpg]" class="mycode_img" /></a></span></span><br />
<br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Qui định thiết kế trong Form:</span></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Các nút lệnh đặt tên có các ký tự đầu là "btn" -&gt; button. Vd: btnAdd. Bạn không được thay đổi tên (name) các nút lênh vì có liên quan đến code gọi trong class. Nếu muốn đổi thì phải đổi đồng bộ luôn trong class.</span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">- Các Textbox dùng để nhập liệu phải đặt thuộc tính Tag=Yes. Mục đích: để code xác định những textbox nào trên form để lấy dữ liệu cũng như gán dữ liệu cho nó. Các textbox này cũng đặt Name trùng với tên Field.</span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Code cho class module: đặt tên <span style="font-weight: bold;" class="mycode_b"><span style="color: #3333cc;" class="mycode_color">clsDataEntry</span></span></span></span><br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">Option&nbsp;Explicit<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mvarButtons</span><span style="color: #007700">(</span><span style="color: #0000BB">11</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">WithEvents&nbsp;mctlForm&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Access</span><span style="color: #007700">.</span><span style="color: #0000BB">Form<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mlblLabelToUpdate&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Access</span><span style="color: #007700">.</span><span style="color: #0000BB">Label<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mlngTotalRecords&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mrstFormRecordset&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">DAO</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrSQL&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mvarBookmark&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Variant<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mctlFocusSave&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mblnAddMode&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mblnEditMode&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mblnDisplayRecordPos&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrSourceTable&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrPrimaryKey&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /><br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">mconBGAddNew&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">13691373&nbsp; &nbsp; </span><span style="color: #DD0000">'RGB(237,&nbsp;233,&nbsp;208)<br />Private&nbsp;Const&nbsp;mconBGSave&nbsp;=&nbsp;16777215<br /><br />Private&nbsp;Sub&nbsp;Class_Initialize()<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Gán&nbsp;các&nbsp;nút&nbsp;lenh&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">Navigation&nbsp;buttons</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">vào&nbsp;</span><span style="color: #007700">Array&nbsp;</span><span style="color: #0000BB">de&nbsp;goi&nbsp;trong&nbsp;hàm&nbsp;</span><span style="color: #DD0000">"processCMD"<br />'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dùng&nbsp;de&nbsp;enabled/disable&nbsp;các&nbsp;nút&nbsp;lenh&nbsp;tuy&nbsp;theo.<br />'&nbsp;</span><span style="color: #0000BB">Chú&nbsp;ý</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB"> &nbsp; Ten&nbsp;các&nbsp;nut&nbsp;lenh&nbsp;trong&nbsp;Form&nbsp;phai&nbsp;dong&nbsp;bo&nbsp;voi&nbsp;code&nbsp;trong&nbsp;</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">này</span><span style="color: #007700">.</span><span style="color: #0000BB">Vd</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">"btnFirst"</span><span style="color: #007700">.<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;So&nbsp;luong&nbsp;các&nbsp;nut&nbsp;lenh&nbsp;cung&nbsp;phai&nbsp;nhat&nbsp;quán.<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /><br /> &nbsp; mvarButtons(0)&nbsp;=&nbsp;"btnFirst"<br /> &nbsp; mvarButtons(1)&nbsp;=&nbsp;"btnPrevious"<br /> &nbsp; mvarButtons(2)&nbsp;=&nbsp;"btnNext"<br /> &nbsp; mvarButtons(3)&nbsp;=&nbsp;"btnLast"<br /> &nbsp; mvarButtons(4)&nbsp;=&nbsp;"btnAdd"<br /> &nbsp; mvarButtons(5)&nbsp;=&nbsp;"btnEdit"<br /> &nbsp; mvarButtons(6)&nbsp;=&nbsp;"btnSave"<br /> &nbsp; mvarButtons(7)&nbsp;=&nbsp;"btnDelete"<br /> &nbsp; mvarButtons(8)&nbsp;=&nbsp;"btnUndo"<br /> &nbsp; mvarButtons(9)&nbsp;=&nbsp;"btnFind"<br /> &nbsp; mvarButtons(10)&nbsp;=&nbsp;"btnExit"<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Class_Initialize",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;Class_Terminate()<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; If&nbsp;Not&nbsp;mrstFormRecordset.EOF&nbsp;Then&nbsp;mrstFormRecordset.Close<br /> &nbsp; Set&nbsp;mrstFormRecordset&nbsp;=&nbsp;Nothing<br /> &nbsp; Set&nbsp;mctlFocusSave&nbsp;=&nbsp;Nothing<br /> &nbsp; Set&nbsp;mctlForm&nbsp;=&nbsp;Nothing<br /> &nbsp; Set&nbsp;mlblLabelToUpdate&nbsp;=&nbsp;Nothing<br /> &nbsp; Erase&nbsp;mvarButtons<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Class_Terminate",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;InitialiseData()<br /><br />'&nbsp;</span><span style="color: #0000BB"> &nbsp;Lay&nbsp;du&nbsp;lieu&nbsp;va&nbsp;hien&nbsp;thi&nbsp;len&nbsp;form<br /></span><span style="color: #DD0000">'<br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;db&nbsp;As&nbsp;DAO.Database<br /><br /> &nbsp; Set&nbsp;db&nbsp;=&nbsp;CurrentDb<br /> &nbsp; Set&nbsp;mrstFormRecordset&nbsp;=&nbsp;db.OpenRecordset(mstrSQL)<br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; If&nbsp;.RecordCount&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;.EOF&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;0<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MoveLast<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;.RecordCount<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MoveFirst<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvarBookmark&nbsp;=&nbsp;.Bookmark&nbsp; '</span><span style="color: #0000BB">Luu&nbsp;vi&nbsp;tri<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;DisplayData<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;With<br /><br /><br /> &nbsp; Call&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">True</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; If&nbsp;mlngTotalRecords&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"0&nbsp;/&nbsp;0"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"1&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Set&nbsp;db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"InitialiseData"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DataEntryOne"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;Function&nbsp;</span><span style="color: #0000BB">KeyAutoIncrement</span><span style="color: #007700">(</span><span style="color: #0000BB">strField</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /><br /></span><span style="color: #DD0000">'&nbsp;Tra&nbsp;ve&nbsp;gia&nbsp;tri&nbsp;True&nbsp;neu&nbsp;Primary&nbsp;Key&nbsp;là&nbsp;AutoNumber.<br />'&nbsp;</span><span style="color: #0000BB">Dung&nbsp;de&nbsp;thiet&nbsp;lap&nbsp;cac&nbsp;thuoc&nbsp;tinh&nbsp;riêng&nbsp;cho&nbsp;Field&nbsp;này&nbsp;trong&nbsp;Form</span><span style="color: #007700">.</span><span style="color: #0000BB">Vd</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Enabled</span><span style="color: #007700">:</span><span style="color: #0000BB">No</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Background</span><span style="color: #007700">...<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; If&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields</span><span style="color: #007700">(</span><span style="color: #0000BB">strField</span><span style="color: #007700">).</span><span style="color: #0000BB">Attributes&nbsp;</span><span style="color: #007700">And&nbsp;</span><span style="color: #0000BB">dbAutoIncrField</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; KeyAutoIncrement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; KeyAutoIncrement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Exit&nbsp;</span><span style="color: #007700">Function<br /><br /></span><span style="color: #0000BB">HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"KeyAutoIncrement"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;</span><span style="color: #007700">Function<br /><br />Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">blnVal&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean</span><span style="color: #007700">)<br /><br /></span><span style="color: #DD0000">'&nbsp;Muc&nbsp;dich:&nbsp; Locked/&nbsp;Unlocked&nbsp;các&nbsp;textbox&nbsp;nhap&nbsp;lieu<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;fld&nbsp;As&nbsp;Field<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; Dim&nbsp;strControlName&nbsp;As&nbsp;Variant<br /><br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset.Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;=&nbsp;mctlForm.Controls(fld.Name)<br /> &nbsp; &nbsp; &nbsp; If&nbsp;ctl.Tag&nbsp;=&nbsp;"yes"&nbsp;Then&nbsp; &nbsp; '</span><span style="color: #0000BB">Phai&nbsp;thiet&nbsp;lap&nbsp;Tag</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Yes&nbsp;cho&nbsp;các&nbsp;textbox&nbsp;dùng&nbsp;nhap&nbsp;lieu</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Bo&nbsp;qua&nbsp;Field&nbsp;Primary&nbsp;key&nbsp;neu&nbsp;nó&nbsp;là&nbsp;Autonumber<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Not&nbsp;KeyAutoIncrement(fld.Name)&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl.Locked&nbsp;=&nbsp;blnVal<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Next&nbsp;fld<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"ToggleControls",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Public&nbsp;Property&nbsp;Set&nbsp;LabelToUpdate(ByVal&nbsp;lblVal&nbsp;As&nbsp;Label)<br />'&nbsp;</span><span style="color: #0000BB"> Khai&nbsp;bao&nbsp;doi&nbsp;tuong&nbsp;label&nbsp;nào&nbsp;dùng&nbsp;de&nbsp;hien&nbsp;thi&nbsp;thong&nbsp;tin&nbsp;record&nbsp;navigation<br /> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Set&nbsp;mlblLabelToUpdate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">lblVal<br /> &nbsp; <br /> &nbsp; Exit&nbsp;Property<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Set&nbsp;LabelToUpdate"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #0000BB">strMsg&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /><br /></span><span style="color: #DD0000">'&nbsp; Cap&nbsp;nhat&nbsp;noi&nbsp;dung&nbsp;lable&nbsp;hien&nbsp;trang&nbsp;record<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; If&nbsp;mblnDisplayRecordPos&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; mlblLabelToUpdate.Caption&nbsp;=&nbsp;strMsg<br /> &nbsp; End&nbsp;If<br /> &nbsp; Exit&nbsp;Sub<br /> &nbsp; <br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"UpdateLabel",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Public&nbsp;Sub&nbsp;ProcessCMD(intIndex&nbsp;As&nbsp;Integer)<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Duoc&nbsp;goi&nbsp;cho&nbsp;moi&nbsp;nút&nbsp;lenh&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">Them</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Xoa</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">tien</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">lùi</span><span style="color: #007700">...).<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;indx:&nbsp;Tham&nbsp;so&nbsp;xác&nbsp;dinh&nbsp;nút&nbsp;nào&nbsp;duoc&nbsp;bam.<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Select&nbsp;Case&nbsp;intIndex<br /> &nbsp; Case&nbsp;0&nbsp; '</span><span style="color: #0000BB">First<br /> &nbsp; &nbsp; &nbsp; mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">MoveFirst<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay</span><span style="color: #007700">(</span><span style="color: #DD0000">"1&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; <br /> &nbsp; Case&nbsp;1&nbsp; </span><span style="color: #DD0000">'Previous<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MovePrevious<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay(.AbsolutePosition&nbsp;+&nbsp;1&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; <br /> &nbsp; Case&nbsp;2&nbsp; '</span><span style="color: #0000BB">Next<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">MoveNext<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay</span><span style="color: #007700">(.</span><span style="color: #0000BB">AbsolutePosition&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; <br /> &nbsp; Case&nbsp;3&nbsp; </span><span style="color: #DD0000">'Last<br /> &nbsp; &nbsp; &nbsp; mrstFormRecordset.MoveLast<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay(mlngTotalRecords&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; <br /> &nbsp; Case&nbsp;4&nbsp; '</span><span style="color: #0000BB">AddNew<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">False</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB"> &nbsp; </span><span style="color: #DD0000">'&nbsp;unlock&nbsp;tat&nbsp;ca&nbsp;textbox&nbsp;nhap&nbsp;lieu<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;FormatControls(mconBGAddNew)&nbsp; '</span><span style="color: #0000BB">Dinh&nbsp;dang&nbsp;background&nbsp;textbox&nbsp;nhap&nbsp;lieu&nbsp;khi&nbsp;them&nbsp;moi<br /> &nbsp; &nbsp; &nbsp; mblnAddMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mlngTotalRecords&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Luu&nbsp;vi&nbsp;tri&nbsp;record&nbsp;truoc&nbsp;khi&nbsp;AddNew.&nbsp;Neu&nbsp;Undo&nbsp;thi&nbsp;se&nbsp;tra&nbsp;vè&nbsp;vi&nbsp;tri&nbsp;cu.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvarBookmark&nbsp;=&nbsp;mrstFormRecordset.Bookmark<br /> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvarBookmark&nbsp;=&nbsp;""<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel("Dòng&nbsp;m"&nbsp;&amp;&nbsp;ChrW(7899)&nbsp;&amp;&nbsp;"i")<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ClearData<br /> &nbsp; <br /> &nbsp; Case&nbsp;5&nbsp; '</span><span style="color: #0000BB">Edit<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'.LockEdits&nbsp;=&nbsp;True&nbsp; '&nbsp;</span><span style="color: #0000BB">Neu&nbsp;trong&nbsp;moi&nbsp;truong&nbsp;da&nbsp;nguoi&nbsp;dung&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">multi&nbsp;users</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">thì&nbsp;dùng&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">LockEdits&nbsp;de&nbsp;bay&nbsp;loi&nbsp;Edit<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ToggleControls</span><span style="color: #007700">(</span><span style="color: #0000BB">False</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; mblnEditMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;FormatControls</span><span style="color: #007700">(</span><span style="color: #0000BB">mconBGAddNew</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; <br /> &nbsp; Case&nbsp;6&nbsp; </span><span style="color: #DD0000">'Save<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ToggleControls(True)<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mblnAddMode&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;AddNewRecord<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;mlngTotalRecords&nbsp;+&nbsp;1<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel(mlngTotalRecords&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;mblnEditMode&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EditRecord<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;FormatControls(mconBGSave)<br /> &nbsp; &nbsp; &nbsp; mblnAddMode&nbsp;=&nbsp;False<br /> &nbsp; &nbsp; &nbsp; mblnEditMode&nbsp;=&nbsp;False<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; <br /> &nbsp; Case&nbsp;7&nbsp; '</span><span style="color: #0000BB">Delete<br /> &nbsp; &nbsp; &nbsp; If&nbsp;MsgBoxUni</span><span style="color: #007700">(</span><span style="color: #DD0000">"B"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7841</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;mu"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7889</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;xóa&nbsp;dòng&nbsp;này?"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vbYesNo</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Xác&nbsp;nh"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7853</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;xóa&nbsp;dòng"</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">vbYes&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;DeleteRecord<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; <br /> &nbsp; Case&nbsp;8&nbsp; </span><span style="color: #DD0000">'Undo<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UndoEdit<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateButtonsState<br /> &nbsp; <br /> &nbsp; '</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">9&nbsp; </span><span style="color: #DD0000">'Find<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Thiet&nbsp;lap&nbsp;rieng&nbsp;frmFind&nbsp;tùy&nbsp;tung&nbsp;form<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; Case&nbsp;10&nbsp; </span><span style="color: #DD0000">'Exit<br /> &nbsp; &nbsp; &nbsp; DoCmd.Close&nbsp;acForm,&nbsp;mctlForm.Name<br /> &nbsp; End&nbsp;Select<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"ProcessCMD",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Public&nbsp;Sub&nbsp;GotoRecord(pkey&nbsp;As&nbsp;Variant)<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Di&nbsp;chuyen&nbsp;toi&nbsp;record&nbsp;chi&nbsp;dinh</span><span style="color: #007700">.&nbsp;(</span><span style="color: #0000BB">Standard&nbsp;Search</span><span style="color: #007700">)<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; pkey:&nbsp;Primary&nbsp;key&nbsp;value<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; .FindFirst&nbsp;mstrPrimaryKey&nbsp;&amp;&nbsp;"="&nbsp;&amp;&nbsp;pkey<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ProcessDisplay(.AbsolutePosition&nbsp;+&nbsp;1&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; End&nbsp;With<br /> &nbsp; Exit&nbsp;Sub<br /> &nbsp; <br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"GoToRecord",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;ProcessDisplay(strMsg&nbsp;As&nbsp;String)<br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Call&nbsp;DisplayData<br /> &nbsp; Call&nbsp;UpdateLabel(strMsg)<br /> &nbsp; Call&nbsp;UpdateButtonsState&nbsp; '</span><span style="color: #0000BB">Phai&nbsp;setfocus&nbsp;vào&nbsp;control&nbsp;khac&nbsp;truoc&nbsp;khi&nbsp;en</span><span style="color: #007700">/</span><span style="color: #0000BB">disable<br /> &nbsp; Exit&nbsp;Sub<br /> &nbsp; <br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ProcessDisplay"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;UndoEdit</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Dùng&nbsp;Unbound&nbsp;form&nbsp;nen&nbsp;chi&nbsp;can&nbsp;tra&nbsp;vè&nbsp;hien&nbsp;trang&nbsp;cu,&nbsp;chua&nbsp;luu&nbsp;du&nbsp;lieu&nbsp;vao&nbsp;table<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /><br /> &nbsp; Call&nbsp;ToggleControls(True)<br /> &nbsp; Call&nbsp;FormatControls(mconBGSave)<br /> &nbsp; If&nbsp;mlngTotalRecords&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mblnAddMode&nbsp;Then&nbsp; &nbsp; '&nbsp;</span><span style="color: #0000BB">Tra&nbsp;ve&nbsp;vi&nbsp;tri&nbsp;record&nbsp;cu&nbsp;truoc&nbsp;khi&nbsp;AddNew<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Bookmark&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarBookmark<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">AbsolutePosition&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;/&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">mlngTotalRecords</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Call&nbsp;DisplayData<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;ClearData<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"0&nbsp;/&nbsp;0"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; mblnAddMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False<br /> &nbsp; mblnEditMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UndoEdit"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;AddNewRecord</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Luu&nbsp;record&nbsp;moi&nbsp;vao&nbsp;table<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; Dim&nbsp;fld&nbsp;As&nbsp;DAO.Field<br /> &nbsp; Dim&nbsp;varField&nbsp;As&nbsp;Variant<br /> &nbsp; Dim&nbsp;indx&nbsp;As&nbsp;Integer<br /><br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; .AddNew<br /> &nbsp; &nbsp; &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset.Fields<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;=&nbsp;mctlForm.Controls(fld.Name)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;ctl.Tag&nbsp;=&nbsp;"yes"&nbsp;Then&nbsp; &nbsp; '</span><span style="color: #0000BB">Chi&nbsp;cap&nbsp;nhat&nbsp;du&nbsp;lieu&nbsp;tu&nbsp;textbox&nbsp;có&nbsp;Tag</span><span style="color: #007700">=</span><span style="color: #0000BB">yes<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varField&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;KeyAutoIncrement</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;=&nbsp;.</span><span style="color: #0000BB">Fields</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Chuyen&nbsp;textbox&nbsp;co&nbsp;zero&nbsp;length&nbsp;thành&nbsp;Null&nbsp;neu&nbsp;can<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mrstFormRecordset(fld.Name)&nbsp;=&nbsp;IIf(varField&nbsp;=&nbsp;"",&nbsp;Null,&nbsp;varField)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; Next&nbsp;fld<br /><br /> &nbsp; &nbsp; &nbsp; .Update<br /> &nbsp; &nbsp; &nbsp; .MoveLast&nbsp; &nbsp; '</span><span style="color: #0000BB">Di&nbsp;chuyen&nbsp;den&nbsp;record&nbsp;vua&nbsp;moi&nbsp;them<br /> &nbsp; End&nbsp;With<br /><br /> &nbsp; RequerySubform<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"AddNewRecord"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;EditRecord</span><span style="color: #007700">()<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /> &nbsp; Dim&nbsp;fld&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Field<br /> &nbsp; Dim&nbsp;varField&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Variant<br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">Edit<br /> &nbsp; &nbsp; &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Tag&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"yes"&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Not&nbsp;KeyAutoIncrement</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varField&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TriM</span><span style="color: #007700">&#36;(</span><span style="color: #0000BB">Nz</span><span style="color: #007700">(</span><span style="color: #0000BB">ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value</span><span style="color: #007700">))<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; varField&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">IIf</span><span style="color: #007700">(</span><span style="color: #0000BB">Len</span><span style="color: #007700">(</span><span style="color: #0000BB">varField</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">varField</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">varField<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Next&nbsp;fld<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">Update<br /> &nbsp; End&nbsp;With<br /><br /> &nbsp; RequerySubform<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EditRecord"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;DeleteRecord</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Dùng&nbsp;phuong&nbsp;thuc&nbsp;.Delete&nbsp;cua&nbsp;DAO&nbsp;Recordset.<br />'&nbsp;</span><span style="color: #0000BB"> Chi&nbsp;dùng&nbsp;duoc&nbsp;cho&nbsp;Recordset&nbsp;dang&nbsp;Dynaset</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">khong&nbsp;duoc&nbsp;cho&nbsp;Snapshot<br /></span><span style="color: #DD0000">'&nbsp; DAO&nbsp;Recordset&nbsp;tu&nbsp;dong&nbsp;Delete&nbsp;ma&nbsp;khong&nbsp;thong&nbsp;bao.&nbsp;Nó&nbsp;khong&nbsp;tu&nbsp;dong&nbsp;di&nbsp;chuyen&nbsp;qua&nbsp;record&nbsp;tiep&nbsp;nên&nbsp;phai&nbsp;.MoveNext<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;lngAbsolutePosition&nbsp;As&nbsp;Long<br /><br /><br /> &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; lngAbsolutePosition&nbsp;=&nbsp;.AbsolutePosition<br /> &nbsp; &nbsp; &nbsp; .Delete<br /> &nbsp; &nbsp; &nbsp; mlngTotalRecords&nbsp;=&nbsp;mlngTotalRecords&nbsp;-&nbsp;1<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mlngTotalRecords&nbsp;=&nbsp;0&nbsp;Then&nbsp; &nbsp; '</span><span style="color: #0000BB">Vua&nbsp;Xoa&nbsp;record&nbsp;cuôi&nbsp;cùng&nbsp;cua&nbsp;recordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;ClearData<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel</span><span style="color: #007700">(</span><span style="color: #DD0000">"0&nbsp;/&nbsp;0"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;lngAbsolutePosition&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mlngTotalRecords&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'Là&nbsp;dong&nbsp;cuoi&nbsp;cùng<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MovePrevious<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lngAbsolutePosition&nbsp;=&nbsp;lngAbsolutePosition&nbsp;+&nbsp;1<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .MoveNext<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;DisplayData<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;UpdateLabel(lngAbsolutePosition&nbsp;&amp;&nbsp;"&nbsp;/&nbsp;"&nbsp;&amp;&nbsp;mlngTotalRecords)<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; End&nbsp;With<br /><br /> &nbsp; Call&nbsp;RequerySubform<br /><br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; If&nbsp;Err.Number&nbsp;=&nbsp;3200&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; MsgBoxUni&nbsp;"B"&nbsp;&amp;&nbsp;ChrW(7841)&nbsp;&amp;&nbsp;"n&nbsp;không&nbsp;th"&nbsp;&amp;&nbsp;ChrW(7875)&nbsp;&amp;&nbsp;"&nbsp;xóa&nbsp;dòng&nbsp;này!"&nbsp;&amp;&nbsp;vbCrLf&nbsp;&amp;&nbsp;ChrW(272)&nbsp;&amp;&nbsp;"ã&nbsp;có&nbsp;d"&nbsp;&amp;&nbsp;ChrW(7919)&nbsp;&amp;&nbsp;"&nbsp;li"&nbsp;&amp;&nbsp;ChrW(7879)&nbsp;&amp;&nbsp;"u&nbsp;phát&nbsp;sinh&nbsp;liên&nbsp;quan.",&nbsp;vbExclamation,&nbsp;"C"&nbsp;&amp;&nbsp;ChrW(7843)&nbsp;&amp;&nbsp;"nh&nbsp;báo."<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"DeleteRecord",&nbsp;"clsDataEntry")<br /> &nbsp; End&nbsp;If<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;DisplayData()<br /><br />'&nbsp;</span><span style="color: #0000BB">Hien&nbsp;thi&nbsp;Record&nbsp;hien&nbsp;tai&nbsp;len&nbsp;Form</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /> &nbsp; Dim&nbsp;fld&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Field<br /> &nbsp; Dim&nbsp;indx&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Integer<br /><br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; If&nbsp;ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Tag&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"yes"&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">).</span><span style="color: #0000BB">Type&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dbDate&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Format</span><span style="color: #007700">(</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"dd/mm/yyyy"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl</span><span style="color: #007700">.</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mrstFormRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Next&nbsp;fld<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DisplayData"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;ClearData</span><span style="color: #007700">()<br /><br /></span><span style="color: #DD0000">'&nbsp; Xoa&nbsp;noi&nbsp;dung&nbsp;textbox<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; Dim&nbsp;fld&nbsp;As&nbsp;Field<br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset.Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;=&nbsp;mctlForm.Controls(fld.Name)<br /> &nbsp; &nbsp; &nbsp; If&nbsp;ctl.Tag&nbsp;=&nbsp;"yes"&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl.Value&nbsp;=&nbsp;""<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Next&nbsp;fld<br /> &nbsp; Exit&nbsp;Sub<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"ClearData",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;RequerySubform()<br /> &nbsp; Dim&nbsp;ctl&nbsp;As&nbsp;Control<br /> &nbsp; For&nbsp;Each&nbsp;ctl&nbsp;In&nbsp;mctlForm.Controls<br /> &nbsp; &nbsp; &nbsp; If&nbsp;ctl.ControlType&nbsp;=&nbsp;acSubform&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctl.Requery<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Next&nbsp;ctl<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;FormatControls(lngColor&nbsp;As&nbsp;Long)<br /><br />'&nbsp;</span><span style="color: #0000BB"> &nbsp;Dinh&nbsp;dang&nbsp;background&nbsp;cua&nbsp;các&nbsp;textnhap&nbsp;lieu</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">màu&nbsp;vàng&nbsp;khi&nbsp;thêm&nbsp;mói</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">tra&nbsp;vè&nbsp;nhu&nbsp;cu&nbsp;khi&nbsp;Save</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; Dim&nbsp;ctl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control<br /> &nbsp; Dim&nbsp;fld&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Field<br /><br /> &nbsp; For&nbsp;Each&nbsp;fld&nbsp;In&nbsp;mrstFormRecordset</span><span style="color: #007700">.</span><span style="color: #0000BB">Fields<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ctl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mctlForm</span><span style="color: #007700">.</span><span style="color: #0000BB">Controls</span><span style="color: #007700">(</span><span style="color: #0000BB">fld</span><span style="color: #007700">.</span><span style="color: #0000BB">Name</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; With&nbsp;ctl<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">Tag&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"yes"&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'&nbsp;Bo&nbsp;qua&nbsp;Field&nbsp;Autonumber<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Not&nbsp;KeyAutoIncrement(fld.Name)&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .BackColor&nbsp;=&nbsp;lngColor<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; Next&nbsp;fld<br /> &nbsp; DoEvents<br /><br />FormatControls_Exit:<br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"FormatControls",&nbsp;"clsDataEntry")<br /> &nbsp; Resume&nbsp;FormatControls_Exit<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;UpdateButtonsState()<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Enabled</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">Disabled&nbsp;các&nbsp;nút&nbsp;lenh&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">Thêm</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Xóa</span><span style="color: #007700">...)<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1=Enabled;&nbsp;0=Disabled.<br />'&nbsp;</span><span style="color: #0000BB">Gán&nbsp;hàng&nbsp;loat&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">11&nbsp;nút&nbsp;lenh</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">dua&nbsp;theo&nbsp;chuoi&nbsp;11&nbsp;ký&nbsp;tu&nbsp;0&nbsp;1&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">strButtonState</span><span style="color: #007700">).<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mctlFocusSave</span><span style="color: #007700">.</span><span style="color: #0000BB">SetFocus<br /> &nbsp; If&nbsp;mblnAddMode&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'Thêm&nbsp;record&nbsp;moi<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00000010100")&nbsp; '</span><span style="color: #0000BB">Vd</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Enable&nbsp;nút&nbsp;Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Huy&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">index&nbsp;6</span><span style="color: #007700">,</span><span style="color: #0000BB">8&nbsp;</span><span style="color: #007700">=</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; ElseIf&nbsp;mblnEditMode&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'Sua&nbsp;record<br /> &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00000010100")<br /> &nbsp; Else&nbsp; &nbsp; '</span><span style="color: #0000BB">Hien&nbsp;trang&nbsp;binh&nbsp;thuong<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mrstFormRecordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">mlngTotalRecords&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons</span><span style="color: #007700">(</span><span style="color: #DD0000">"00001000001"</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB"> &nbsp;</span><span style="color: #DD0000">'Enable&nbsp;nút&nbsp;Them,&nbsp;Dóng<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElseIf&nbsp;mlngTotalRecords&nbsp;=&nbsp;1&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00001101001")&nbsp; &nbsp;'</span><span style="color: #0000BB">Them</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Sua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Xoa<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElseIf&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">AbsolutePosition&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0&nbsp;Then&nbsp; &nbsp; </span><span style="color: #DD0000">'dang&nbsp;o&nbsp;record&nbsp;dau&nbsp;tien<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons("00111101011")<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElseIf&nbsp;(.AbsolutePosition&nbsp;=&nbsp;mlngTotalRecords&nbsp;-&nbsp;1)&nbsp;Then&nbsp; &nbsp; '&nbsp;</span><span style="color: #0000BB">dang&nbsp;o&nbsp;record&nbsp;cuoi<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons</span><span style="color: #007700">(</span><span style="color: #DD0000">"11001101011"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call&nbsp;EnableDisableButtons</span><span style="color: #007700">(</span><span style="color: #DD0000">"11111101011"</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB"> </span><span style="color: #DD0000">'&nbsp;dang&nbsp;o&nbsp;các&nbsp;record&nbsp;giua<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; End&nbsp;If<br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"UpdateButtonsState",&nbsp;"clsDataEntry")<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;EnableDisableButtons(strButtonState&nbsp;As&nbsp;String)<br /><br />'&nbsp;</span><span style="color: #0000BB">Muc&nbsp;dich</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB"> &nbsp;Enable</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">Disable&nbsp;hàng&nbsp;loat&nbsp;</span><span style="color: #007700">Array&nbsp;(</span><span style="color: #0000BB">11&nbsp;nút&nbsp;lenh</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">dua&nbsp;theo&nbsp;chuoi&nbsp;11&nbsp;ký&nbsp;tu&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;(</span><span style="color: #0000BB">strButtonState</span><span style="color: #007700">).<br /></span><span style="color: #DD0000">'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1=enabled;&nbsp;0=disabled<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Dim&nbsp;intindx&nbsp;As&nbsp;Integer<br /> &nbsp; Dim&nbsp;intButtonLength&nbsp;As&nbsp;Integer<br /> &nbsp; Dim&nbsp;strEnabled&nbsp;As&nbsp;String<br /><br /> &nbsp; strButtonState&nbsp;=&nbsp;TriM&#36;(strButtonState)<br /> &nbsp; intButtonLength&nbsp;=&nbsp;Len(strButtonState)<br /> &nbsp; For&nbsp;intindx&nbsp;=&nbsp;1&nbsp;To&nbsp;intButtonLength<br /> &nbsp; &nbsp; &nbsp; strEnabled&nbsp;=&nbsp;Mid&#36;(strButtonState,&nbsp;intindx,&nbsp;1)<br /> &nbsp; &nbsp; &nbsp; With&nbsp;mctlForm.Controls(mvarButtons(intindx&nbsp;-&nbsp;1))<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;.Enabled&nbsp;&lt;&gt;&nbsp;(strEnabled&nbsp;=&nbsp;"1")&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Enabled&nbsp;=&nbsp;(strEnabled&nbsp;=&nbsp;"1")<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /> &nbsp; Next&nbsp;intindx<br /> &nbsp; DoEvents<br /><br />EnableDisableButtons_Exit:<br /> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; Exit&nbsp;Sub<br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"EnableDisableButtons",&nbsp;"clsDataEntry")<br /> &nbsp; Resume&nbsp;EnableDisableButtons_Exit<br />End&nbsp;Sub<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;FormRecordsetSQL(ByVal&nbsp;sSQL&nbsp;As&nbsp;String)<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; mstrSQL&nbsp;=&nbsp;sSQL&nbsp; &nbsp; '&nbsp;</span><span style="color: #0000BB">Truyen&nbsp;cau&nbsp;lenh&nbsp;SQL&nbsp;làm&nbsp;Form&nbsp;Recordset<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;FormRecordsetSQL"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Set&nbsp;FocusControl</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;cValue&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Control</span><span style="color: #007700">)<br /></span><span style="color: #DD0000">'&nbsp;Khi&nbsp;thiet&nbsp;lap&nbsp;Disable&nbsp;control&nbsp;bat&nbsp;buoc&nbsp;phai&nbsp;focus&nbsp;vào&nbsp;1&nbsp;control&nbsp;khác&nbsp;nó.<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Set&nbsp;mctlFocusSave&nbsp;=&nbsp;cValue<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Property&nbsp;Set&nbsp;FocusControl",&nbsp;"clsDataEntry")<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;SourceTable(ByVal&nbsp;sSourceTableName&nbsp;As&nbsp;String)<br />'&nbsp;</span><span style="color: #0000BB"> Gan&nbsp;thuoc&nbsp;tinh&nbsp;nay&nbsp;de&nbsp;du&nbsp;phong</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">Chua&nbsp;dùng&nbsp;den&nbsp;trong&nbsp;</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">này</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mstrSourceTable&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sSourceTableName<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;SourceTable"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;SourceTableName</span><span style="color: #007700">()<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; SourceTableName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mstrSourceTable<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Get&nbsp;SourceTable"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;DisplayRecordPosition</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;blnShowHide&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean</span><span style="color: #007700">)<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mblnDisplayRecordPos&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">blnShowHide<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;DisplayRecordPosition"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;PrimaryKey</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;sPKFieldName&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /><br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">HandleError<br /> &nbsp; mstrPrimaryKey&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sPKFieldName<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; Call&nbsp;basHandleError</span><span style="color: #007700">.</span><span style="color: #0000BB">LogError</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Property&nbsp;Let&nbsp;PrimaryKey"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clsDataEntry"</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Set&nbsp;FormCtl</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;frmVal&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Access</span><span style="color: #007700">.</span><span style="color: #0000BB">Form</span><span style="color: #007700">)<br /></span><span style="color: #DD0000">'frmVal:&nbsp;Gan&nbsp;Form&nbsp;chua&nbsp;cac&nbsp;NavButton&nbsp;xu&nbsp;ly&nbsp;cho&nbsp;class<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;HandleError<br /> &nbsp; Set&nbsp;mctlForm&nbsp;=&nbsp;frmVal<br /> &nbsp; Call&nbsp;InitialiseData<br /> &nbsp; Exit&nbsp;Property<br /><br />HandleError:<br /> &nbsp; Call&nbsp;basHandleError.LogError(Err.Number,&nbsp;Err.Description,&nbsp;"",&nbsp;"Property&nbsp;Set&nbsp;FormCtl",&nbsp;"clsDataEntry")<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Code cho Form thì chỉ cần khởi tạo class ở sự kiện Form_Open là các nút lệnh có thể chạy: tham khảo thêm trong file.</span></span><br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="https://flic.kr/p/S1DWk7" target="_blank" rel="noopener" class="mycode_url"><img src="https://farm5.staticflickr.com/4826/32825240308_22ac954636_c.jpg" loading="lazy"  alt="[Hình: 32825240308_22ac954636_c.jpg]" class="mycode_img" /></a></span></span><br />
<br />
<br />
<br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font">Link demo: <a href="http://www.mediafire.com/file/rzynj8tcera43e3/DataEntry_NavigationButtons_Class.rar/file" target="_blank" rel="noopener" class="mycode_url">http://www</a></span></span><br />
<span style="font-size: medium;" class="mycode_size"><span style="font-family: Georgia;" class="mycode_font"><a href="http://www.mediafire.com/file/rzynj8tcera43e3/DataEntry_NavigationButtons_Class.rar/file" target="_blank" rel="noopener" class="mycode_url">.mediafire.com/file/rzynj8tcera43e3/DataEntry_NavigationButtons_Class.rar/file</a></span></span><br />
<br />
<br />
<img src="https://i.imgur.com/0buuZ3A.gif" loading="lazy"  alt="[Hình: 0buuZ3A.gif]" class="mycode_img" />]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Class ADO - Kết nối SQL Server (Demo)]]></title>
			<link>https://thuthuataccess.com/forum/thread-10003.html</link>
			<pubDate>Fri, 02 Jun 2017 08:42:21 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=16696">ongke0711</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-10003.html</guid>
			<description><![CDATA[<span style="font-family: Tahoma;" class="mycode_font">Sau khi bạn Dân gợi ý mình nên ngâm cứu chuyển qua lập trình ADO kết hợp với SQL Server (trước giờ chỉ dùng DAO) thì mình cũng đã tìm tòi, sưu tầm, học hỏi…nên cũng bắt đầu nắm được một số cái cơ bản của việc sử dụng thư viện ADO với provider OLEDB để kết nối với SQL server. Bên cạnh đó nó cũng kết nối với nhiều loại CSDL khác.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">Nay mình chia sẽ cái Class ADO dùng kết nối với 3 loại CSDL: SQLServer, Access, Excel</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Class này cũng là dạng cơ bản chi có cái tích hợp thêm các chuỗi kết nối tùy từng loại CSDL sẽ đưa ra chuỗi Connection tương ứng. Mình thấy nó cũng phù hợp vì trong 1 ứng dụng thường sẽ có phần lấy dữ liệu từ Excel nên đưa vô sẳn class cho tiện.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Class có hàm để chạy các Stored Procedure cũng như các câu lệnh SQL.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Mình có sử dụng kỹ thuật kiểm tra IP của bạn Dân để kiểm tra Server online hay không trước khi chạy kết nối chứ không nó chạy mất mấy phút rồi mới báo lỗi kết nối. Bên cạnh đó cũng kiểm tra đường dẫn OK không đối với kết nối máy trong mạng LAN.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Tôi dùng CSDL Northwind và các stored proc của nó để test trong demo này. Các bạn chạy file "SQL2000SampleDb.msi" đính kèm trong folder để cài dữ liệu mẫu của Northwind lên SQL Server nhé.</span><br />
<br />
<span style="font-family: Tahoma;" class="mycode_font"><span style="color: #ff3333;" class="mycode_color">Tuy nhiên có 1 vấn đề này cần các bạn hỗ trợ đó là: mình không truyền được tham số (parameter) dạng ngày\tháng cho store proc trong demo này (stored proc 4, 5 trong demo)</span>.<span style="color: #ff3333;" class="mycode_color"> Các tham số khác (2, 3 tham số) thì truyền bình thường và chạy tốt. Các bạn kinh nghiệm qua vụ này hướng dẫn sửa giùm nhe. Loay hoay với nó suốt mà làm chưa được.</span></span><br />
<br />
<span style="color: #3333ff;" class="mycode_color"><span style="font-family: Tahoma;" class="mycode_font"><span style="font-style: italic;" class="mycode_i">Cập nhật:</span></span></span><br />
<span style="font-family: Tahoma;" class="mycode_font"><span style="color: #3333ff;" class="mycode_color"><span style="font-style: italic;" class="mycode_i">Vụ này mình đã sửa được rồi. Đó là do tên của Stored Procs có khoảng trắng nên nó báo lỗi chứ không phải do tham số truyền vào sai. </span></span> <span style="color: #ff3333;" class="mycode_color"><img src="https://thuthuataccess.com/forum/../backlink/images/smilies/Zing/007.gif" alt="007" title="007" class="smilie smilie_193" /></span> </span><br />
<br />
<br />
<span style="font-family: Tahoma;" class="mycode_font">Các bạn xem qua và đóng góp ý kiến để học hỏi thêm nhé.</span><br />
<br />
<span style="font-family: Tahoma;" class="mycode_font"><a href="https://flic.kr/p/VbZVrn" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4280/34911374811_0a3f48c387_b.jpg" loading="lazy"  alt="[Hình: 34911374811_0a3f48c387_b.jpg]" class="mycode_img" /></a></span><br />
<br />
<a href="https://flic.kr/p/VbZVnK" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4262/34911374601_d9b3073fb0_b.jpg" loading="lazy"  alt="[Hình: 34911374601_d9b3073fb0_b.jpg]" class="mycode_img" /></a><br />
<br />
<a href="https://flic.kr/p/Vk5dRG" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4238/35002745826_867f80aab2.jpg" loading="lazy"  alt="[Hình: 35002745826_867f80aab2.jpg]" class="mycode_img" /></a>  <a href="https://flic.kr/p/VbZVmT" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4242/34911374551_2f8dcbb173.jpg" loading="lazy"  alt="[Hình: 34911374551_2f8dcbb173.jpg]" class="mycode_img" /></a><br />
<br />
Code cho Class ADO.<br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">Option&nbsp;Explicit<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mobjConn&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;Object&nbsp;</span><span style="color: #DD0000">'ADODB.Connection<br /><br />Private&nbsp;mblnIntegratedSecurity&nbsp; &nbsp; &nbsp; As&nbsp;Boolean<br />Private&nbsp;mstrModuleName&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;String&nbsp; &nbsp;'</span><span style="color: #0000BB">Dung&nbsp;trong&nbsp;thong&nbsp;bao&nbsp;loi</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">error&nbsp;trap<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrConnectionString&nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrCurrentServer&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrCurrentDatabase&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrDatabaseType&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;DBaseType<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mlngRecordCount&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long<br /><br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adUseClient&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adLockReadOnly&nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adCmdStoredProc&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">4<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adParamOutput&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adOpenDynamic&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adOpenstatic&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Enum&nbsp;DBaseType<br /> &nbsp; dbSQLServer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br /> &nbsp; dbAccess&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br /> &nbsp; dbExcel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br />End&nbsp;Enum<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Enum&nbsp;EditMode<br /> &nbsp; ReadOnly&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0<br /> &nbsp; EditAddDelete&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br />End&nbsp;Enum<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;Class_Initialize</span><span style="color: #007700">()<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br /> &nbsp; mstrModuleName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"clsADOConnectDB"<br /></span><span style="color: #0000BB"> &nbsp; </span><span style="color: #DD0000">'Set&nbsp;mobjConn&nbsp;=&nbsp;New&nbsp;ADODB.Connection<br /> &nbsp; Set&nbsp;mobjConn&nbsp;=&nbsp;CreateObject("ADODB.Connection")<br /> &nbsp; &nbsp;<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;Class_Terminate()<br /> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; mobjConn.Close<br /> &nbsp; Set&nbsp;mobjConn&nbsp;=&nbsp;Nothing<br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;0<br /> &nbsp; &nbsp;<br />End&nbsp;Sub<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;ConnectionString()&nbsp;As&nbsp;String<br /> &nbsp; ConnectionString&nbsp;=&nbsp;mstrConnectionString<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;ConnectionString(ByVal&nbsp;NewValue&nbsp;As&nbsp;String)<br /> &nbsp; mstrConnectionString&nbsp;=&nbsp;NewValue<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;CommandTimeOut()&nbsp;As&nbsp;Integer<br /> &nbsp; CommandTimeOut&nbsp;=&nbsp;mobjConn.CommandTimeOut<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;CommandTimeOut(ByVal&nbsp;NewTimeOut&nbsp;As&nbsp;Integer)<br /> &nbsp; mobjConn.CommandTimeOut&nbsp;=&nbsp;NewTimeOut<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;CurrentDatabase()&nbsp;As&nbsp;Integer<br /> &nbsp; &nbsp;'</span><span style="color: #0000BB">Read</span><span style="color: #007700">-</span><span style="color: #0000BB">only&nbsp;property<br /> &nbsp; CurrentDatabase&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mstrCurrentDatabase<br />End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;CurrentServer</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br /> &nbsp; &nbsp;</span><span style="color: #DD0000">'Read-only&nbsp;property<br /> &nbsp; CurrentServer&nbsp;=&nbsp;mstrCurrentServer<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;DatabaseType()&nbsp;As&nbsp;DBaseType<br /> &nbsp; DatabaseType&nbsp;=&nbsp;mstrDatabaseType<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;DatabaseType(ByVal&nbsp;NewValue&nbsp;As&nbsp;DBaseType)<br /> &nbsp; mstrDatabaseType&nbsp;=&nbsp;NewValue<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;IntegratedSecurity()&nbsp;As&nbsp;Boolean<br /> &nbsp; IntegratedSecurity&nbsp;=&nbsp;mblnIntegratedSecurity<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;IntegratedSecurity(ByVal&nbsp;NewValue&nbsp;As&nbsp;Boolean)<br /> &nbsp; mblnIntegratedSecurity&nbsp;=&nbsp;NewValue<br />End&nbsp;Property<br /><br />Public&nbsp;Sub&nbsp;CloseDB()<br />'</span><span style="color: #0000BB">Dong&nbsp;ket&nbsp;noi&nbsp;toi&nbsp;Database<br /> &nbsp; If&nbsp;Not&nbsp;mobjConn&nbsp;Is&nbsp;Nothing&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; If&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">State&nbsp;</span><span style="color: #007700">And&nbsp;</span><span style="color: #0000BB">adStateOpen</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">Close<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;mobjConn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">ConnectDB</span><span style="color: #007700">(</span><span style="color: #0000BB">Optional&nbsp;ByVal&nbsp;DatabaseType&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">DBaseType&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;TargetServer&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;TargetDatabase&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;IntegratedSecurity&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #DD0000">'------------------------------------------------------------------------------------------<br />'</span><span style="color: #0000BB">Mo&nbsp;ket&nbsp;noi&nbsp;toi&nbsp;Server&nbsp;và&nbsp;Database&nbsp;chi&nbsp;dinh</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">Nêu&nbsp;không&nbsp;có&nbsp;tham&nbsp;so&nbsp;thì&nbsp;dùng&nbsp;lai&nbsp;ket&nbsp;noi&nbsp;cu</span><span style="color: #007700">.<br /></span><span style="color: #DD0000">'------------------------------------------------------------------------------------------<br /><br /> &nbsp; Dim&nbsp;blnNewConnect&nbsp;As&nbsp;Boolean<br /> &nbsp; Dim&nbsp;blnReturn&nbsp;As&nbsp;Boolean<br /> &nbsp; Dim&nbsp;strDataSource&nbsp;As&nbsp;String<br /> &nbsp; Dim&nbsp;strDB&nbsp;As&nbsp;String<br /> &nbsp; Dim&nbsp;strConn&nbsp;As&nbsp;String<br /> &nbsp; Dim&nbsp;vError&nbsp;As&nbsp;Variant<br /> &nbsp; Dim&nbsp;sErrors&nbsp;As&nbsp;String<br /><br /> &nbsp; blnReturn&nbsp;=&nbsp;True<br /> &nbsp; blnNewConnect&nbsp;=&nbsp;True<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;ConnectDBError<br /><br /> &nbsp; If&nbsp;Not&nbsp;mobjConn&nbsp;Is&nbsp;Nothing&nbsp;Then&nbsp; &nbsp;'</span><span style="color: #0000BB">Kiem&nbsp;tra&nbsp;xem&nbsp;có&nbsp;Connection&nbsp;chua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">có&nbsp;rôi&nbsp;thi&nbsp;dung&nbsp;ket&nbsp;noi&nbsp;cu<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">State&nbsp;</span><span style="color: #007700">And&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp;Then&nbsp; </span><span style="color: #DD0000">'-&gt;&nbsp;Da&nbsp;có&nbsp;ket&nbsp;noi<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blnNewConnect&nbsp;=&nbsp;False<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; End&nbsp;If<br /><br /> &nbsp; If&nbsp;blnNewConnect&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Tao&nbsp;ket&nbsp;noi&nbsp;moi<br /> &nbsp; &nbsp; &nbsp; If&nbsp;TargetServer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""&nbsp;</span><span style="color: #007700">Or&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Neu&nbsp;khong&nbsp;chi&nbsp;dinh&nbsp;ten&nbsp;Server,&nbsp;Database&nbsp;thì&nbsp;dùng&nbsp;lai&nbsp;Connection&nbsp;cu&nbsp;voi&nbsp;tham&nbsp;so&nbsp;cu<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len(mstrConnectionString)&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strConn&nbsp;=&nbsp;mstrConnectionString<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Xay&nbsp;dung&nbsp;chuoi&nbsp;ket&nbsp;noi&nbsp;moi&nbsp;bang&nbsp;hàm&nbsp;BuilConnectionString<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strConn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">BuildConnectionString</span><span style="color: #007700">(</span><span style="color: #0000BB">mstrDatabaseType</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrCurrentServer</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrCurrentDatabase</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mblnIntegratedSecurity</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Xay&nbsp;dung&nbsp;chuoi&nbsp;ket&nbsp;noi&nbsp;moi&nbsp;bang&nbsp;hàm&nbsp;BuilConnectionString&nbsp;voi&nbsp;cac&nbsp;tham&nbsp;so&nbsp;cung&nbsp;cap<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strConn&nbsp;=&nbsp;BuildConnectionString(DatabaseType,&nbsp;TargetServer,&nbsp;TargetDatabase,&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mblnIntegratedSecurity)<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; mobjConn.ConnectionString&nbsp;=&nbsp;strConn<br /> &nbsp; &nbsp; &nbsp; mobjConn.Open<br /> &nbsp; End&nbsp;If<br /><br />ConnectDBResume:<br /> &nbsp; ConnectDB&nbsp;=&nbsp;blnReturn<br /> &nbsp; Exit&nbsp;Function<br /><br />ConnectDBError:<br /> &nbsp; blnReturn&nbsp;=&nbsp;False<br /> &nbsp; '</span><span style="color: #0000BB">ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ConnectDB"<br /></span><span style="color: #0000BB"> &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number<br /> &nbsp; Case&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">2147467259<br /> &nbsp; &nbsp; &nbsp; MsgBoxUni&nbsp;</span><span style="color: #DD0000">"Thông&nbsp;s"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7889</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;k"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7871</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"t&nbsp;n"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7889</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"i&nbsp;d"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7919</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;li"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7879</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"u&nbsp;không&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">273</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"úng."</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">vbCritical</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Thông&nbsp;báo"<br /></span><span style="color: #0000BB"> &nbsp; Case&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">2147217843<br /> &nbsp; &nbsp; &nbsp; MsgBoxUni&nbsp;</span><span style="color: #DD0000">"Sai&nbsp;tên&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">273</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">259</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"ng&nbsp;nh"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7853</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"p&nbsp;ho"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7863</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"c&nbsp;m"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7853</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"t&nbsp;kh"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7849</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"u."</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">vbCritical</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Thông&nbsp;báo"<br /></span><span style="color: #0000BB"> &nbsp; Case&nbsp;</span><span style="color: #007700">Else<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ConnectDB"<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;Select<br /> &nbsp; Resume&nbsp;ConnectDBResume<br /><br />End&nbsp;</span><span style="color: #007700">Function<br /><br />Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">BuildConnectionString</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;DatabaseType&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">DBaseType</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ByVal&nbsp;TargetServer&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ByVal&nbsp;TargetDatabase&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ByVal&nbsp;IntegratedSecurity&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;UserID&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;Password&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br /><br /> &nbsp; Dim&nbsp;strExt&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp; </span><span style="color: #DD0000">'Extension&nbsp;cua&nbsp;Excel&nbsp;file:&nbsp;xls,xlsx,xlsm,xlsb<br /><br /> &nbsp; '</span><span style="color: #0000BB">Xay&nbsp;dung&nbsp;chuoi&nbsp;ket&nbsp;noi<br /> &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">DatabaseType<br /> &nbsp; Case&nbsp;1&nbsp; &nbsp;</span><span style="color: #DD0000">'SQLServer<br /> &nbsp; &nbsp; &nbsp; If&nbsp;Len(UserID)&nbsp;Then&nbsp; '</span><span style="color: #0000BB">Có&nbsp;Username</span><span style="color: #007700">/</span><span style="color: #0000BB">Pass&nbsp;dang&nbsp;nhap<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Network&nbsp;Library=DBMSSOCN;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"PROVIDER=SQLOLEDB;DATA&nbsp;SOURCE="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";INITIAL&nbsp;CATALOG="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";User&nbsp;Id="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">UserID&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";Password="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">Password&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'"Provider=SQLNCLI10;"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Network&nbsp;Library=DBMSSOCN;Provider=SQLOLEDB;"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Server="&nbsp;&amp;&nbsp;TargetServer&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Database="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Trusted_Connection=Yes;"<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; <br /> &nbsp; Case&nbsp;2&nbsp; &nbsp;'</span><span style="color: #0000BB">MS&nbsp;Access<br /> &nbsp; &nbsp; &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">glngAppVersion<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;10<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len</span><span style="color: #007700">(</span><span style="color: #0000BB">Password</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.Jet.OLEDB.4.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Jet&nbsp;OLEDB:Database&nbsp;Password="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">Password&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.Jet.OLEDB.4.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Case&nbsp;Is&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">10<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len</span><span style="color: #007700">(</span><span style="color: #0000BB">Password</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.ACE.OLEDB.12.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Jet&nbsp;OLEDB:Database&nbsp;Password="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">Password&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.ACE.OLEDB.12.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";Persist&nbsp;Security&nbsp;Info=False;"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;Select<br /> &nbsp; Case&nbsp;3&nbsp; &nbsp;</span><span style="color: #DD0000">'MS&nbsp;Excel<br /> &nbsp; <br /> &nbsp; &nbsp; &nbsp; strExt&nbsp;=&nbsp;UCase(Mid(TargetDatabase,&nbsp;InStrRev(TargetDatabase,&nbsp;".")&nbsp;+&nbsp;1))<br /> &nbsp; &nbsp; &nbsp; Select&nbsp;Case&nbsp;strExt<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLSX"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Extended&nbsp;Properties&nbsp;=&nbsp;'</span><span style="color: #0000BB">Excel&nbsp;12.0&nbsp;Xml</span><span style="color: #007700">;</span><span style="color: #0000BB">HDR</span><span style="color: #007700">=</span><span style="color: #0000BB">YES</span><span style="color: #DD0000">'"<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLSB"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Extended&nbsp;Properties&nbsp;=&nbsp;'</span><span style="color: #0000BB">Excel&nbsp;12.0</span><span style="color: #007700">;</span><span style="color: #0000BB">HDR</span><span style="color: #007700">=</span><span style="color: #0000BB">YES</span><span style="color: #DD0000">'"<br /><br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLSM"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Extended&nbsp;Properties&nbsp;=&nbsp;'</span><span style="color: #0000BB">Excel&nbsp;12.0&nbsp;Macro</span><span style="color: #007700">;</span><span style="color: #0000BB">HDR</span><span style="color: #007700">=</span><span style="color: #0000BB">YES</span><span style="color: #DD0000">'"<br /><br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLS"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">to&nbsp;connect&nbsp;Excel&nbsp;97</span><span style="color: #007700">-</span><span style="color: #0000BB">2003&nbsp;from&nbsp;Excel&nbsp;2007</span><span style="color: #007700">+<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Extended&nbsp;Properties&nbsp;=&nbsp;'Excel&nbsp;8.0;HDR=YES'"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;Select<br /> &nbsp; Case&nbsp;</span><span style="color: #007700">Else<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Truong&nbsp;hop&nbsp;Database&nbsp;khac,&nbsp;tu&nbsp;dieu&nbsp;chinh&nbsp;chuoi&nbsp;ket&nbsp;noi&nbsp;lai&nbsp;cho&nbsp;phu&nbsp;hop<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=SQLOLEDB;Server="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";Database="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";Trusted_Connection=yes;"<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;Select<br /><br /> &nbsp; mstrCurrentServer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TargetServer<br /> &nbsp; mstrCurrentDatabase&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TargetDatabase<br /> &nbsp; mstrDatabaseType&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DatabaseType<br /> &nbsp; mblnIntegratedSecurity&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">IntegratedSecurity<br /> &nbsp; BuildConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mstrConnectionString<br /><br />End&nbsp;</span><span style="color: #007700">Function<br /><br />Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;SQLConnection</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">Object&nbsp;</span><span style="color: #DD0000">'ADODB.Connection<br /> &nbsp; '</span><span style="color: #0000BB">Tra&nbsp;ve&nbsp;Conn&nbsp;object</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; If&nbsp;Not&nbsp;mobjConn&nbsp;Is&nbsp;Nothing&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;SQLConnection&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mobjConn<br /> &nbsp; &nbsp; &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">0<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /><br /></span><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">GetRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">strSQL&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Optional&nbsp;EMode&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">EditMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Object&nbsp; &nbsp; </span><span style="color: #DD0000">'ADODB.Recordset<br /><br /> &nbsp; Dim&nbsp;objRSet&nbsp;As&nbsp;Object&nbsp; &nbsp; '</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /><br /> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">GRError<br /> &nbsp; mlngRecordCount&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0<br /><br /> &nbsp; If&nbsp;ConnectDB</span><span style="color: #007700">()&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Set&nbsp;objRSet&nbsp;=&nbsp;New&nbsp;ADODB.Recordset<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;objRSet&nbsp;=&nbsp;CreateObject("ADODB.Recordset")<br /> &nbsp; &nbsp; &nbsp; objRSet.CursorLocation&nbsp;=&nbsp;adUseClient<br /> &nbsp; &nbsp; &nbsp; objRSet.Open&nbsp;strSQL,&nbsp;mobjConn,&nbsp;adOpenKeyset,&nbsp;adLockOptimistic<br /> &nbsp; &nbsp; &nbsp; mlngRecordCount&nbsp;=&nbsp;objRSet.RecordCount<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;GetRecordset&nbsp;=&nbsp;objRSet<br /><br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Ngat&nbsp;ket&nbsp;noi&nbsp;Recorset&nbsp;voi&nbsp;Database&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">disconnect&nbsp;connection</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">EMode<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;0&nbsp; </span><span style="color: #DD0000">'ReadOnly<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objRSet.ActiveConnection&nbsp;=&nbsp;Nothing<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;1&nbsp; '</span><span style="color: #0000BB">EditAddDelete<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Khong&nbsp;dong&nbsp;connection<br /> &nbsp; &nbsp; &nbsp; End&nbsp;Select<br /><br /> &nbsp; End&nbsp;If<br /><br />GRResume:<br /> &nbsp; CloseDB<br /> &nbsp; Exit&nbsp;Function<br /><br />GRError:<br /> &nbsp; ShowErrorMessages&nbsp;Err,&nbsp;mstrModuleName,&nbsp;"GetRecordset"<br /> &nbsp; Resume&nbsp;GRResume<br /><br />End&nbsp;Function<br /><br />Public&nbsp;Sub&nbsp;ExecuteQuery(SQLToExecute&nbsp;As&nbsp;String,&nbsp;Optional&nbsp;CloseDatabase&nbsp;As&nbsp;Boolean&nbsp;=&nbsp;True)<br /><br />'</span><span style="color: #0000BB">Dung&nbsp;de&nbsp;thuc&nbsp;thi&nbsp;cau&nbsp;lenh&nbsp;Select&nbsp;Query&nbsp;SQL<br /><br /> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">EAQError<br /><br /> &nbsp; Dim&nbsp;rs&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /> &nbsp; If&nbsp;ConnectDB</span><span style="color: #007700">()&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;rs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">Execute</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLToExecute</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /><br /></span><span style="color: #0000BB">EAQResume</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; If&nbsp;CloseDatabase&nbsp;Then&nbsp;CloseDB<br /> &nbsp; Exit&nbsp;Sub<br /><br />EAQError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ExecuteActionQuery"<br /></span><span style="color: #0000BB"> &nbsp; Resume&nbsp;EAQResume<br /><br />End&nbsp;Sub<br /><br /></span><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">ExecuteActionQuery</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLToExecute&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Optional&nbsp;CloseDatabase&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /><br /></span><span style="color: #DD0000">'Dung&nbsp;de&nbsp;thuc&nbsp;thi&nbsp;cau&nbsp;lenh&nbsp;Action&nbsp;Query&nbsp;SQL<br /> &nbsp; Dim&nbsp;blnReturn&nbsp;As&nbsp;Boolean<br /><br /> &nbsp; blnReturn&nbsp;=&nbsp;True<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;EAQError<br /><br /> &nbsp; If&nbsp;ConnectDB()&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; mobjConn.Execute&nbsp;SQLToExecute<br /> &nbsp; End&nbsp;If<br /> &nbsp; Exit&nbsp;Function<br /><br />EAQResume:<br /> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; If&nbsp;CloseDatabase&nbsp;Or&nbsp;Not&nbsp;blnReturn&nbsp;Then&nbsp;CloseDB<br /> &nbsp; ExecuteActionQuery&nbsp;=&nbsp;blnReturn<br /> &nbsp; Exit&nbsp;Function<br /><br />EAQError:<br /> &nbsp; blnReturn&nbsp;=&nbsp;False<br /> &nbsp; ShowErrorMessages&nbsp;Err,&nbsp;mstrModuleName,&nbsp;"ExecuteActionQuery"<br /> &nbsp; Resume&nbsp;EAQResume<br /><br />End&nbsp;Function<br /><br />Public&nbsp;Function&nbsp;ExecuteSPWithADOCommand(StoredProcName&nbsp;As&nbsp;String,&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputParameter&nbsp;As&nbsp;String,&nbsp;OutputValue&nbsp;As&nbsp;Variant,&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ParamArray&nbsp;InputParameters()&nbsp;As&nbsp;Variant)&nbsp;As&nbsp;ADODB.Recordset<br />'</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Phai&nbsp;la&nbsp;1&nbsp;cap&nbsp;Ten&nbsp;arameter&nbsp;có&nbsp;ký&nbsp;tu&nbsp;</span><span style="color: #007700">@&nbsp;</span><span style="color: #0000BB">o&nbsp;dau&nbsp;va&nbsp;Gia&nbsp;tri&nbsp;Para</span><span style="color: #007700">.<br /></span><span style="color: #DD0000">'Neu&nbsp;nhieu&nbsp;Param&nbsp;thi&nbsp;cu&nbsp;viet&nbsp;noi&nbsp;tiep&nbsp;thanh&nbsp;tung&nbsp;cap,&nbsp;cách&nbsp;nhay&nbsp;dau&nbsp;phay.<br />'</span><span style="color: #0000BB">OutputParmeter&nbsp;cung&nbsp;them&nbsp;ky&nbsp;tu&nbsp;</span><span style="color: #007700">@&nbsp;</span><span style="color: #0000BB">o&nbsp;dau</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; Dim&nbsp;objCmd&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Command<br /> &nbsp; Dim&nbsp;rsCmd&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /> &nbsp; Dim&nbsp;intParam&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Integer<br /> &nbsp; </span><span style="color: #DD0000">'Dim&nbsp;recordsAffected&nbsp;As&nbsp;Long<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;ESPError<br /><br /> &nbsp; If&nbsp;ConnectDB()&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;objCmd&nbsp;=&nbsp;New&nbsp;ADODB.Command<br /> &nbsp; &nbsp; &nbsp; With&nbsp;objCmd<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .ActiveConnection&nbsp;=&nbsp;mobjConn<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .CommandText&nbsp;=&nbsp;StoredProcName<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .CommandType&nbsp;=&nbsp;adCmdStoredProc<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Parameters.Refresh<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Lay&nbsp;tham&nbsp;so<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For&nbsp;intParam&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0&nbsp;To&nbsp;UBound</span><span style="color: #007700">(</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Step&nbsp;2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">Parameters</span><span style="color: #007700">(</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam</span><span style="color: #007700">)).</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Debug</span><span style="color: #007700">.Print&nbsp;</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"-"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next&nbsp;intParam<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Xac&nbsp;dinh&nbsp;co&nbsp;tham&nbsp;so&nbsp;Output&nbsp;khong<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len(Trim(OutputParameter))&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Parameters(OutputParameter).Direction&nbsp;=&nbsp;adParamOutput<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #007700">.</span><span style="color: #0000BB">Execute<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;rsCmd&nbsp;</span><span style="color: #007700">=&nbsp;New&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rsCmd</span><span style="color: #007700">.</span><span style="color: #0000BB">Open&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">Execute</span><span style="color: #007700">(</span><span style="color: #0000BB">recordsAffected</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /><br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ExecuteSPWithADOCommand&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rsCmd<br /><br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Lay&nbsp;gia&nbsp;tri&nbsp;cho&nbsp;Output&nbsp;Para<br /> &nbsp; &nbsp; &nbsp; If&nbsp;Len(Trim(OutputParameter))&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputValue&nbsp;=&nbsp;objCmd.Parameters(OutputParameter).Value<br /> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputValue&nbsp;=&nbsp;vbNullString<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Neu&nbsp;bi&nbsp;mat&nbsp;ket&nbsp;noi&nbsp;nhung&nbsp;khong&nbsp;bi&nbsp;loi&nbsp;phat&nbsp;sinh<br /> &nbsp; &nbsp; &nbsp; OutputValue&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">vbNullString<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ExecuteSPWithADOCommand&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Exit&nbsp;</span><span style="color: #007700">Function<br /></span><span style="color: #0000BB"> &nbsp; <br />ESPResume</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; Set&nbsp;ExecuteSPWithADOCommand&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; Set&nbsp;objCmd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; CloseDB<br /> &nbsp; Exit&nbsp;</span><span style="color: #007700">Function<br /><br /></span><span style="color: #0000BB">ESPError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ExecuteSPWithADOCommand"<br /></span><span style="color: #0000BB"> &nbsp; Resume&nbsp;ESPResume<br /><br />End&nbsp;</span><span style="color: #007700">Function<br /><br /><br /><br />Public&nbsp;</span><span style="color: #0000BB">Sub&nbsp;ShowErrorMessages</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;StandardErrorObject&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">VBA</span><span style="color: #007700">.</span><span style="color: #0000BB">ErrObject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; ByVal&nbsp;SourceModule&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ByVal&nbsp;SourceMethod&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br /> &nbsp; </span><span style="color: #DD0000">'Su&nbsp;dung&nbsp;cho&nbsp;bay&nbsp;loi&nbsp;cua&nbsp;class.<br /> &nbsp; Dim&nbsp;strMsg&nbsp;As&nbsp;String<br /> &nbsp; &nbsp;<br /> &nbsp; '</span><span style="color: #0000BB">Loi&nbsp;co&nbsp;ban&nbsp;cua&nbsp;he&nbsp;thong</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; If&nbsp;StandardErrorObject</span><span style="color: #007700">.</span><span style="color: #0000BB">Number&nbsp;</span><span style="color: #007700">&lt;&gt;&nbsp;</span><span style="color: #0000BB">0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; strMsg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Error:&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">CStr</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"Description:&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br /> &nbsp; strMsg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strMsg&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">SourceModule&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"::"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">SourceMethod&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf<br /> &nbsp; &nbsp;<br /> &nbsp; Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Clear<br /> &nbsp; &nbsp;<br /> &nbsp; MsgBoxUni&nbsp;strMsg</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">vbCritical</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Liên&nbsp;h"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7879</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;ng"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">432</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7901</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"i&nbsp;qu"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7843</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;tr"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7883</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;ch"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">432</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">417</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"ng&nbsp;trình&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">273</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7875</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;tr"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7907</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;giúp"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br />End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
<br />
<br />
Link file: <a href="http://www.mediafire.com/file/b28rf1vflxjcwwu/KetNoiSQLServer_ClassADO_Demo.rar" target="_blank" rel="noopener" class="mycode_url">http://www.mediafire.com/file/b28rf1vflx...O_Demo.rar</a>]]></description>
			<content:encoded><![CDATA[<span style="font-family: Tahoma;" class="mycode_font">Sau khi bạn Dân gợi ý mình nên ngâm cứu chuyển qua lập trình ADO kết hợp với SQL Server (trước giờ chỉ dùng DAO) thì mình cũng đã tìm tòi, sưu tầm, học hỏi…nên cũng bắt đầu nắm được một số cái cơ bản của việc sử dụng thư viện ADO với provider OLEDB để kết nối với SQL server. Bên cạnh đó nó cũng kết nối với nhiều loại CSDL khác.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">Nay mình chia sẽ cái Class ADO dùng kết nối với 3 loại CSDL: SQLServer, Access, Excel</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Class này cũng là dạng cơ bản chi có cái tích hợp thêm các chuỗi kết nối tùy từng loại CSDL sẽ đưa ra chuỗi Connection tương ứng. Mình thấy nó cũng phù hợp vì trong 1 ứng dụng thường sẽ có phần lấy dữ liệu từ Excel nên đưa vô sẳn class cho tiện.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Class có hàm để chạy các Stored Procedure cũng như các câu lệnh SQL.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Mình có sử dụng kỹ thuật kiểm tra IP của bạn Dân để kiểm tra Server online hay không trước khi chạy kết nối chứ không nó chạy mất mấy phút rồi mới báo lỗi kết nối. Bên cạnh đó cũng kiểm tra đường dẫn OK không đối với kết nối máy trong mạng LAN.</span><br />
<span style="font-family: Tahoma;" class="mycode_font">- Tôi dùng CSDL Northwind và các stored proc của nó để test trong demo này. Các bạn chạy file "SQL2000SampleDb.msi" đính kèm trong folder để cài dữ liệu mẫu của Northwind lên SQL Server nhé.</span><br />
<br />
<span style="font-family: Tahoma;" class="mycode_font"><span style="color: #ff3333;" class="mycode_color">Tuy nhiên có 1 vấn đề này cần các bạn hỗ trợ đó là: mình không truyền được tham số (parameter) dạng ngày\tháng cho store proc trong demo này (stored proc 4, 5 trong demo)</span>.<span style="color: #ff3333;" class="mycode_color"> Các tham số khác (2, 3 tham số) thì truyền bình thường và chạy tốt. Các bạn kinh nghiệm qua vụ này hướng dẫn sửa giùm nhe. Loay hoay với nó suốt mà làm chưa được.</span></span><br />
<br />
<span style="color: #3333ff;" class="mycode_color"><span style="font-family: Tahoma;" class="mycode_font"><span style="font-style: italic;" class="mycode_i">Cập nhật:</span></span></span><br />
<span style="font-family: Tahoma;" class="mycode_font"><span style="color: #3333ff;" class="mycode_color"><span style="font-style: italic;" class="mycode_i">Vụ này mình đã sửa được rồi. Đó là do tên của Stored Procs có khoảng trắng nên nó báo lỗi chứ không phải do tham số truyền vào sai. </span></span> <span style="color: #ff3333;" class="mycode_color"><img src="https://thuthuataccess.com/forum/../backlink/images/smilies/Zing/007.gif" alt="007" title="007" class="smilie smilie_193" /></span> </span><br />
<br />
<br />
<span style="font-family: Tahoma;" class="mycode_font">Các bạn xem qua và đóng góp ý kiến để học hỏi thêm nhé.</span><br />
<br />
<span style="font-family: Tahoma;" class="mycode_font"><a href="https://flic.kr/p/VbZVrn" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4280/34911374811_0a3f48c387_b.jpg" loading="lazy"  alt="[Hình: 34911374811_0a3f48c387_b.jpg]" class="mycode_img" /></a></span><br />
<br />
<a href="https://flic.kr/p/VbZVnK" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4262/34911374601_d9b3073fb0_b.jpg" loading="lazy"  alt="[Hình: 34911374601_d9b3073fb0_b.jpg]" class="mycode_img" /></a><br />
<br />
<a href="https://flic.kr/p/Vk5dRG" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4238/35002745826_867f80aab2.jpg" loading="lazy"  alt="[Hình: 35002745826_867f80aab2.jpg]" class="mycode_img" /></a>  <a href="https://flic.kr/p/VbZVmT" target="_blank" rel="noopener" class="mycode_url"><img src="https://c1.staticflickr.com/5/4242/34911374551_2f8dcbb173.jpg" loading="lazy"  alt="[Hình: 34911374551_2f8dcbb173.jpg]" class="mycode_img" /></a><br />
<br />
Code cho Class ADO.<br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">Option&nbsp;Explicit<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mobjConn&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;Object&nbsp;</span><span style="color: #DD0000">'ADODB.Connection<br /><br />Private&nbsp;mblnIntegratedSecurity&nbsp; &nbsp; &nbsp; As&nbsp;Boolean<br />Private&nbsp;mstrModuleName&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;String&nbsp; &nbsp;'</span><span style="color: #0000BB">Dung&nbsp;trong&nbsp;thong&nbsp;bao&nbsp;loi</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">error&nbsp;trap<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrConnectionString&nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrCurrentServer&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrCurrentDatabase&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String<br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mstrDatabaseType&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;DBaseType<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">mlngRecordCount&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long<br /><br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adUseClient&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adLockReadOnly&nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adCmdStoredProc&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">4<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adParamOutput&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adOpenDynamic&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br /></span><span style="color: #007700">Private&nbsp;Const&nbsp;</span><span style="color: #0000BB">adOpenstatic&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; As&nbsp;Long&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Enum&nbsp;DBaseType<br /> &nbsp; dbSQLServer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br /> &nbsp; dbAccess&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br /> &nbsp; dbExcel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br />End&nbsp;Enum<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Enum&nbsp;EditMode<br /> &nbsp; ReadOnly&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0<br /> &nbsp; EditAddDelete&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br />End&nbsp;Enum<br /><br /></span><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;Class_Initialize</span><span style="color: #007700">()<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br /> &nbsp; mstrModuleName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"clsADOConnectDB"<br /></span><span style="color: #0000BB"> &nbsp; </span><span style="color: #DD0000">'Set&nbsp;mobjConn&nbsp;=&nbsp;New&nbsp;ADODB.Connection<br /> &nbsp; Set&nbsp;mobjConn&nbsp;=&nbsp;CreateObject("ADODB.Connection")<br /> &nbsp; &nbsp;<br />End&nbsp;Sub<br /><br />Private&nbsp;Sub&nbsp;Class_Terminate()<br /> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; mobjConn.Close<br /> &nbsp; Set&nbsp;mobjConn&nbsp;=&nbsp;Nothing<br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;0<br /> &nbsp; &nbsp;<br />End&nbsp;Sub<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;ConnectionString()&nbsp;As&nbsp;String<br /> &nbsp; ConnectionString&nbsp;=&nbsp;mstrConnectionString<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;ConnectionString(ByVal&nbsp;NewValue&nbsp;As&nbsp;String)<br /> &nbsp; mstrConnectionString&nbsp;=&nbsp;NewValue<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;CommandTimeOut()&nbsp;As&nbsp;Integer<br /> &nbsp; CommandTimeOut&nbsp;=&nbsp;mobjConn.CommandTimeOut<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;CommandTimeOut(ByVal&nbsp;NewTimeOut&nbsp;As&nbsp;Integer)<br /> &nbsp; mobjConn.CommandTimeOut&nbsp;=&nbsp;NewTimeOut<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;CurrentDatabase()&nbsp;As&nbsp;Integer<br /> &nbsp; &nbsp;'</span><span style="color: #0000BB">Read</span><span style="color: #007700">-</span><span style="color: #0000BB">only&nbsp;property<br /> &nbsp; CurrentDatabase&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mstrCurrentDatabase<br />End&nbsp;Property<br /><br /></span><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;CurrentServer</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br /> &nbsp; &nbsp;</span><span style="color: #DD0000">'Read-only&nbsp;property<br /> &nbsp; CurrentServer&nbsp;=&nbsp;mstrCurrentServer<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;DatabaseType()&nbsp;As&nbsp;DBaseType<br /> &nbsp; DatabaseType&nbsp;=&nbsp;mstrDatabaseType<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;DatabaseType(ByVal&nbsp;NewValue&nbsp;As&nbsp;DBaseType)<br /> &nbsp; mstrDatabaseType&nbsp;=&nbsp;NewValue<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Get&nbsp;IntegratedSecurity()&nbsp;As&nbsp;Boolean<br /> &nbsp; IntegratedSecurity&nbsp;=&nbsp;mblnIntegratedSecurity<br />End&nbsp;Property<br /><br />Public&nbsp;Property&nbsp;Let&nbsp;IntegratedSecurity(ByVal&nbsp;NewValue&nbsp;As&nbsp;Boolean)<br /> &nbsp; mblnIntegratedSecurity&nbsp;=&nbsp;NewValue<br />End&nbsp;Property<br /><br />Public&nbsp;Sub&nbsp;CloseDB()<br />'</span><span style="color: #0000BB">Dong&nbsp;ket&nbsp;noi&nbsp;toi&nbsp;Database<br /> &nbsp; If&nbsp;Not&nbsp;mobjConn&nbsp;Is&nbsp;Nothing&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; If&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">State&nbsp;</span><span style="color: #007700">And&nbsp;</span><span style="color: #0000BB">adStateOpen</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">Close<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;mobjConn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB">End&nbsp;Sub<br /><br /></span><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">ConnectDB</span><span style="color: #007700">(</span><span style="color: #0000BB">Optional&nbsp;ByVal&nbsp;DatabaseType&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">DBaseType&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;TargetServer&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;TargetDatabase&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;IntegratedSecurity&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">False</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /></span><span style="color: #DD0000">'------------------------------------------------------------------------------------------<br />'</span><span style="color: #0000BB">Mo&nbsp;ket&nbsp;noi&nbsp;toi&nbsp;Server&nbsp;và&nbsp;Database&nbsp;chi&nbsp;dinh</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">Nêu&nbsp;không&nbsp;có&nbsp;tham&nbsp;so&nbsp;thì&nbsp;dùng&nbsp;lai&nbsp;ket&nbsp;noi&nbsp;cu</span><span style="color: #007700">.<br /></span><span style="color: #DD0000">'------------------------------------------------------------------------------------------<br /><br /> &nbsp; Dim&nbsp;blnNewConnect&nbsp;As&nbsp;Boolean<br /> &nbsp; Dim&nbsp;blnReturn&nbsp;As&nbsp;Boolean<br /> &nbsp; Dim&nbsp;strDataSource&nbsp;As&nbsp;String<br /> &nbsp; Dim&nbsp;strDB&nbsp;As&nbsp;String<br /> &nbsp; Dim&nbsp;strConn&nbsp;As&nbsp;String<br /> &nbsp; Dim&nbsp;vError&nbsp;As&nbsp;Variant<br /> &nbsp; Dim&nbsp;sErrors&nbsp;As&nbsp;String<br /><br /> &nbsp; blnReturn&nbsp;=&nbsp;True<br /> &nbsp; blnNewConnect&nbsp;=&nbsp;True<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;ConnectDBError<br /><br /> &nbsp; If&nbsp;Not&nbsp;mobjConn&nbsp;Is&nbsp;Nothing&nbsp;Then&nbsp; &nbsp;'</span><span style="color: #0000BB">Kiem&nbsp;tra&nbsp;xem&nbsp;có&nbsp;Connection&nbsp;chua</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">có&nbsp;rôi&nbsp;thi&nbsp;dung&nbsp;ket&nbsp;noi&nbsp;cu<br /> &nbsp; &nbsp; &nbsp; If&nbsp;mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">State&nbsp;</span><span style="color: #007700">And&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">adStateOpen&nbsp;Then&nbsp; </span><span style="color: #DD0000">'-&gt;&nbsp;Da&nbsp;có&nbsp;ket&nbsp;noi<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blnNewConnect&nbsp;=&nbsp;False<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; End&nbsp;If<br /><br /> &nbsp; If&nbsp;blnNewConnect&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Tao&nbsp;ket&nbsp;noi&nbsp;moi<br /> &nbsp; &nbsp; &nbsp; If&nbsp;TargetServer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""&nbsp;</span><span style="color: #007700">Or&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">""&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Neu&nbsp;khong&nbsp;chi&nbsp;dinh&nbsp;ten&nbsp;Server,&nbsp;Database&nbsp;thì&nbsp;dùng&nbsp;lai&nbsp;Connection&nbsp;cu&nbsp;voi&nbsp;tham&nbsp;so&nbsp;cu<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len(mstrConnectionString)&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strConn&nbsp;=&nbsp;mstrConnectionString<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Xay&nbsp;dung&nbsp;chuoi&nbsp;ket&nbsp;noi&nbsp;moi&nbsp;bang&nbsp;hàm&nbsp;BuilConnectionString<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strConn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">BuildConnectionString</span><span style="color: #007700">(</span><span style="color: #0000BB">mstrDatabaseType</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrCurrentServer</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrCurrentDatabase</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mblnIntegratedSecurity</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Xay&nbsp;dung&nbsp;chuoi&nbsp;ket&nbsp;noi&nbsp;moi&nbsp;bang&nbsp;hàm&nbsp;BuilConnectionString&nbsp;voi&nbsp;cac&nbsp;tham&nbsp;so&nbsp;cung&nbsp;cap<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strConn&nbsp;=&nbsp;BuildConnectionString(DatabaseType,&nbsp;TargetServer,&nbsp;TargetDatabase,&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mblnIntegratedSecurity)<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; mobjConn.ConnectionString&nbsp;=&nbsp;strConn<br /> &nbsp; &nbsp; &nbsp; mobjConn.Open<br /> &nbsp; End&nbsp;If<br /><br />ConnectDBResume:<br /> &nbsp; ConnectDB&nbsp;=&nbsp;blnReturn<br /> &nbsp; Exit&nbsp;Function<br /><br />ConnectDBError:<br /> &nbsp; blnReturn&nbsp;=&nbsp;False<br /> &nbsp; '</span><span style="color: #0000BB">ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ConnectDB"<br /></span><span style="color: #0000BB"> &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number<br /> &nbsp; Case&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">2147467259<br /> &nbsp; &nbsp; &nbsp; MsgBoxUni&nbsp;</span><span style="color: #DD0000">"Thông&nbsp;s"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7889</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;k"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7871</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"t&nbsp;n"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7889</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"i&nbsp;d"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7919</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;li"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7879</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"u&nbsp;không&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">273</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"úng."</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">vbCritical</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Thông&nbsp;báo"<br /></span><span style="color: #0000BB"> &nbsp; Case&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">2147217843<br /> &nbsp; &nbsp; &nbsp; MsgBoxUni&nbsp;</span><span style="color: #DD0000">"Sai&nbsp;tên&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">273</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">259</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"ng&nbsp;nh"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7853</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"p&nbsp;ho"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7863</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"c&nbsp;m"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7853</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"t&nbsp;kh"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7849</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"u."</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">vbCritical</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Thông&nbsp;báo"<br /></span><span style="color: #0000BB"> &nbsp; Case&nbsp;</span><span style="color: #007700">Else<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ConnectDB"<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;Select<br /> &nbsp; Resume&nbsp;ConnectDBResume<br /><br />End&nbsp;</span><span style="color: #007700">Function<br /><br />Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">BuildConnectionString</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;DatabaseType&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">DBaseType</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ByVal&nbsp;TargetServer&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ByVal&nbsp;TargetDatabase&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ByVal&nbsp;IntegratedSecurity&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;UserID&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional&nbsp;ByVal&nbsp;Password&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br /><br /> &nbsp; Dim&nbsp;strExt&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp; </span><span style="color: #DD0000">'Extension&nbsp;cua&nbsp;Excel&nbsp;file:&nbsp;xls,xlsx,xlsm,xlsb<br /><br /> &nbsp; '</span><span style="color: #0000BB">Xay&nbsp;dung&nbsp;chuoi&nbsp;ket&nbsp;noi<br /> &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">DatabaseType<br /> &nbsp; Case&nbsp;1&nbsp; &nbsp;</span><span style="color: #DD0000">'SQLServer<br /> &nbsp; &nbsp; &nbsp; If&nbsp;Len(UserID)&nbsp;Then&nbsp; '</span><span style="color: #0000BB">Có&nbsp;Username</span><span style="color: #007700">/</span><span style="color: #0000BB">Pass&nbsp;dang&nbsp;nhap<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Network&nbsp;Library=DBMSSOCN;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"PROVIDER=SQLOLEDB;DATA&nbsp;SOURCE="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";INITIAL&nbsp;CATALOG="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";User&nbsp;Id="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">UserID&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";Password="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">Password&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'"Provider=SQLNCLI10;"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Network&nbsp;Library=DBMSSOCN;Provider=SQLOLEDB;"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Server="&nbsp;&amp;&nbsp;TargetServer&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Database="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Trusted_Connection=Yes;"<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; <br /> &nbsp; Case&nbsp;2&nbsp; &nbsp;'</span><span style="color: #0000BB">MS&nbsp;Access<br /> &nbsp; &nbsp; &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">glngAppVersion<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;10<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len</span><span style="color: #007700">(</span><span style="color: #0000BB">Password</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.Jet.OLEDB.4.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Jet&nbsp;OLEDB:Database&nbsp;Password="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">Password&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.Jet.OLEDB.4.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Case&nbsp;Is&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">10<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len</span><span style="color: #007700">(</span><span style="color: #0000BB">Password</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.ACE.OLEDB.12.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Jet&nbsp;OLEDB:Database&nbsp;Password="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">Password&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.ACE.OLEDB.12.0;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";Persist&nbsp;Security&nbsp;Info=False;"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;Select<br /> &nbsp; Case&nbsp;3&nbsp; &nbsp;</span><span style="color: #DD0000">'MS&nbsp;Excel<br /> &nbsp; <br /> &nbsp; &nbsp; &nbsp; strExt&nbsp;=&nbsp;UCase(Mid(TargetDatabase,&nbsp;InStrRev(TargetDatabase,&nbsp;".")&nbsp;+&nbsp;1))<br /> &nbsp; &nbsp; &nbsp; Select&nbsp;Case&nbsp;strExt<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLSX"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Extended&nbsp;Properties&nbsp;=&nbsp;'</span><span style="color: #0000BB">Excel&nbsp;12.0&nbsp;Xml</span><span style="color: #007700">;</span><span style="color: #0000BB">HDR</span><span style="color: #007700">=</span><span style="color: #0000BB">YES</span><span style="color: #DD0000">'"<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLSB"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Extended&nbsp;Properties&nbsp;=&nbsp;'</span><span style="color: #0000BB">Excel&nbsp;12.0</span><span style="color: #007700">;</span><span style="color: #0000BB">HDR</span><span style="color: #007700">=</span><span style="color: #0000BB">YES</span><span style="color: #DD0000">'"<br /><br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLSM"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;=&nbsp;"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;&amp;&nbsp;TargetDatabase&nbsp;&amp;&nbsp;";"&nbsp;&amp;&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Extended&nbsp;Properties&nbsp;=&nbsp;'</span><span style="color: #0000BB">Excel&nbsp;12.0&nbsp;Macro</span><span style="color: #007700">;</span><span style="color: #0000BB">HDR</span><span style="color: #007700">=</span><span style="color: #0000BB">YES</span><span style="color: #DD0000">'"<br /><br /> &nbsp; &nbsp; &nbsp; Case&nbsp;"XLS"<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">to&nbsp;connect&nbsp;Excel&nbsp;97</span><span style="color: #007700">-</span><span style="color: #0000BB">2003&nbsp;from&nbsp;Excel&nbsp;2007</span><span style="color: #007700">+<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=Microsoft.ACE.OLEDB.12.0;Data&nbsp;Source="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">"Extended&nbsp;Properties&nbsp;=&nbsp;'Excel&nbsp;8.0;HDR=YES'"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;Select<br /> &nbsp; Case&nbsp;</span><span style="color: #007700">Else<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Truong&nbsp;hop&nbsp;Database&nbsp;khac,&nbsp;tu&nbsp;dieu&nbsp;chinh&nbsp;chuoi&nbsp;ket&nbsp;noi&nbsp;lai&nbsp;cho&nbsp;phu&nbsp;hop<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">mstrConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Provider=SQLOLEDB;Server="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetServer&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #DD0000">";Database="&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">TargetDatabase&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">";Trusted_Connection=yes;"<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;Select<br /><br /> &nbsp; mstrCurrentServer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TargetServer<br /> &nbsp; mstrCurrentDatabase&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TargetDatabase<br /> &nbsp; mstrDatabaseType&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DatabaseType<br /> &nbsp; mblnIntegratedSecurity&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">IntegratedSecurity<br /> &nbsp; BuildConnectionString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mstrConnectionString<br /><br />End&nbsp;</span><span style="color: #007700">Function<br /><br />Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;SQLConnection</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">Object&nbsp;</span><span style="color: #DD0000">'ADODB.Connection<br /> &nbsp; '</span><span style="color: #0000BB">Tra&nbsp;ve&nbsp;Conn&nbsp;object</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; If&nbsp;Not&nbsp;mobjConn&nbsp;Is&nbsp;Nothing&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;SQLConnection&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mobjConn<br /> &nbsp; &nbsp; &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">0<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB">End&nbsp;Property<br /><br /><br /></span><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">GetRecordset</span><span style="color: #007700">(</span><span style="color: #0000BB">strSQL&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Optional&nbsp;EMode&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">EditMode&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Object&nbsp; &nbsp; </span><span style="color: #DD0000">'ADODB.Recordset<br /><br /> &nbsp; Dim&nbsp;objRSet&nbsp;As&nbsp;Object&nbsp; &nbsp; '</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /><br /> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">GRError<br /> &nbsp; mlngRecordCount&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0<br /><br /> &nbsp; If&nbsp;ConnectDB</span><span style="color: #007700">()&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Set&nbsp;objRSet&nbsp;=&nbsp;New&nbsp;ADODB.Recordset<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;objRSet&nbsp;=&nbsp;CreateObject("ADODB.Recordset")<br /> &nbsp; &nbsp; &nbsp; objRSet.CursorLocation&nbsp;=&nbsp;adUseClient<br /> &nbsp; &nbsp; &nbsp; objRSet.Open&nbsp;strSQL,&nbsp;mobjConn,&nbsp;adOpenKeyset,&nbsp;adLockOptimistic<br /> &nbsp; &nbsp; &nbsp; mlngRecordCount&nbsp;=&nbsp;objRSet.RecordCount<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;GetRecordset&nbsp;=&nbsp;objRSet<br /><br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Ngat&nbsp;ket&nbsp;noi&nbsp;Recorset&nbsp;voi&nbsp;Database&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">disconnect&nbsp;connection</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; Select&nbsp;</span><span style="color: #007700">Case&nbsp;</span><span style="color: #0000BB">EMode<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;0&nbsp; </span><span style="color: #DD0000">'ReadOnly<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objRSet.ActiveConnection&nbsp;=&nbsp;Nothing<br /> &nbsp; &nbsp; &nbsp; Case&nbsp;1&nbsp; '</span><span style="color: #0000BB">EditAddDelete<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Khong&nbsp;dong&nbsp;connection<br /> &nbsp; &nbsp; &nbsp; End&nbsp;Select<br /><br /> &nbsp; End&nbsp;If<br /><br />GRResume:<br /> &nbsp; CloseDB<br /> &nbsp; Exit&nbsp;Function<br /><br />GRError:<br /> &nbsp; ShowErrorMessages&nbsp;Err,&nbsp;mstrModuleName,&nbsp;"GetRecordset"<br /> &nbsp; Resume&nbsp;GRResume<br /><br />End&nbsp;Function<br /><br />Public&nbsp;Sub&nbsp;ExecuteQuery(SQLToExecute&nbsp;As&nbsp;String,&nbsp;Optional&nbsp;CloseDatabase&nbsp;As&nbsp;Boolean&nbsp;=&nbsp;True)<br /><br />'</span><span style="color: #0000BB">Dung&nbsp;de&nbsp;thuc&nbsp;thi&nbsp;cau&nbsp;lenh&nbsp;Select&nbsp;Query&nbsp;SQL<br /><br /> &nbsp; On&nbsp;Error&nbsp;</span><span style="color: #007700">GoTo&nbsp;</span><span style="color: #0000BB">EAQError<br /><br /> &nbsp; Dim&nbsp;rs&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /> &nbsp; If&nbsp;ConnectDB</span><span style="color: #007700">()&nbsp;</span><span style="color: #0000BB">Then<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;rs&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mobjConn</span><span style="color: #007700">.</span><span style="color: #0000BB">Execute</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLToExecute</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /><br /></span><span style="color: #0000BB">EAQResume</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; If&nbsp;CloseDatabase&nbsp;Then&nbsp;CloseDB<br /> &nbsp; Exit&nbsp;Sub<br /><br />EAQError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ExecuteActionQuery"<br /></span><span style="color: #0000BB"> &nbsp; Resume&nbsp;EAQResume<br /><br />End&nbsp;Sub<br /><br /></span><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">ExecuteActionQuery</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLToExecute&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Optional&nbsp;CloseDatabase&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Boolean&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /><br /></span><span style="color: #DD0000">'Dung&nbsp;de&nbsp;thuc&nbsp;thi&nbsp;cau&nbsp;lenh&nbsp;Action&nbsp;Query&nbsp;SQL<br /> &nbsp; Dim&nbsp;blnReturn&nbsp;As&nbsp;Boolean<br /><br /> &nbsp; blnReturn&nbsp;=&nbsp;True<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;EAQError<br /><br /> &nbsp; If&nbsp;ConnectDB()&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; mobjConn.Execute&nbsp;SQLToExecute<br /> &nbsp; End&nbsp;If<br /> &nbsp; Exit&nbsp;Function<br /><br />EAQResume:<br /> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; If&nbsp;CloseDatabase&nbsp;Or&nbsp;Not&nbsp;blnReturn&nbsp;Then&nbsp;CloseDB<br /> &nbsp; ExecuteActionQuery&nbsp;=&nbsp;blnReturn<br /> &nbsp; Exit&nbsp;Function<br /><br />EAQError:<br /> &nbsp; blnReturn&nbsp;=&nbsp;False<br /> &nbsp; ShowErrorMessages&nbsp;Err,&nbsp;mstrModuleName,&nbsp;"ExecuteActionQuery"<br /> &nbsp; Resume&nbsp;EAQResume<br /><br />End&nbsp;Function<br /><br />Public&nbsp;Function&nbsp;ExecuteSPWithADOCommand(StoredProcName&nbsp;As&nbsp;String,&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputParameter&nbsp;As&nbsp;String,&nbsp;OutputValue&nbsp;As&nbsp;Variant,&nbsp;_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ParamArray&nbsp;InputParameters()&nbsp;As&nbsp;Variant)&nbsp;As&nbsp;ADODB.Recordset<br />'</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">Phai&nbsp;la&nbsp;1&nbsp;cap&nbsp;Ten&nbsp;arameter&nbsp;có&nbsp;ký&nbsp;tu&nbsp;</span><span style="color: #007700">@&nbsp;</span><span style="color: #0000BB">o&nbsp;dau&nbsp;va&nbsp;Gia&nbsp;tri&nbsp;Para</span><span style="color: #007700">.<br /></span><span style="color: #DD0000">'Neu&nbsp;nhieu&nbsp;Param&nbsp;thi&nbsp;cu&nbsp;viet&nbsp;noi&nbsp;tiep&nbsp;thanh&nbsp;tung&nbsp;cap,&nbsp;cách&nbsp;nhay&nbsp;dau&nbsp;phay.<br />'</span><span style="color: #0000BB">OutputParmeter&nbsp;cung&nbsp;them&nbsp;ky&nbsp;tu&nbsp;</span><span style="color: #007700">@&nbsp;</span><span style="color: #0000BB">o&nbsp;dau</span><span style="color: #007700">.<br /><br /></span><span style="color: #0000BB"> &nbsp; Dim&nbsp;objCmd&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Command<br /> &nbsp; Dim&nbsp;rsCmd&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /> &nbsp; Dim&nbsp;intParam&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Integer<br /> &nbsp; </span><span style="color: #DD0000">'Dim&nbsp;recordsAffected&nbsp;As&nbsp;Long<br /><br /> &nbsp; On&nbsp;Error&nbsp;GoTo&nbsp;ESPError<br /><br /> &nbsp; If&nbsp;ConnectDB()&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;objCmd&nbsp;=&nbsp;New&nbsp;ADODB.Command<br /> &nbsp; &nbsp; &nbsp; With&nbsp;objCmd<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .ActiveConnection&nbsp;=&nbsp;mobjConn<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .CommandText&nbsp;=&nbsp;StoredProcName<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .CommandType&nbsp;=&nbsp;adCmdStoredProc<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Parameters.Refresh<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Lay&nbsp;tham&nbsp;so<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For&nbsp;intParam&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0&nbsp;To&nbsp;UBound</span><span style="color: #007700">(</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">Step&nbsp;2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #007700">.</span><span style="color: #0000BB">Parameters</span><span style="color: #007700">(</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam</span><span style="color: #007700">)).</span><span style="color: #0000BB">Value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Debug</span><span style="color: #007700">.Print&nbsp;</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"-"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">InputParameters</span><span style="color: #007700">(</span><span style="color: #0000BB">intParam&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next&nbsp;intParam<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Xac&nbsp;dinh&nbsp;co&nbsp;tham&nbsp;so&nbsp;Output&nbsp;khong<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If&nbsp;Len(Trim(OutputParameter))&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Parameters(OutputParameter).Direction&nbsp;=&nbsp;adParamOutput<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #007700">.</span><span style="color: #0000BB">Execute<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set&nbsp;rsCmd&nbsp;</span><span style="color: #007700">=&nbsp;New&nbsp;</span><span style="color: #0000BB">ADODB</span><span style="color: #007700">.</span><span style="color: #0000BB">Recordset<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rsCmd</span><span style="color: #007700">.</span><span style="color: #0000BB">Open&nbsp;</span><span style="color: #007700">.</span><span style="color: #0000BB">Execute</span><span style="color: #007700">(</span><span style="color: #0000BB">recordsAffected</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp; &nbsp; End&nbsp;With<br /><br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ExecuteSPWithADOCommand&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rsCmd<br /><br /> &nbsp; &nbsp; &nbsp; </span><span style="color: #DD0000">'Lay&nbsp;gia&nbsp;tri&nbsp;cho&nbsp;Output&nbsp;Para<br /> &nbsp; &nbsp; &nbsp; If&nbsp;Len(Trim(OutputParameter))&nbsp;&gt;&nbsp;0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputValue&nbsp;=&nbsp;objCmd.Parameters(OutputParameter).Value<br /> &nbsp; &nbsp; &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputValue&nbsp;=&nbsp;vbNullString<br /> &nbsp; &nbsp; &nbsp; End&nbsp;If<br /> &nbsp; Else<br /> &nbsp; &nbsp; &nbsp; '</span><span style="color: #0000BB">Neu&nbsp;bi&nbsp;mat&nbsp;ket&nbsp;noi&nbsp;nhung&nbsp;khong&nbsp;bi&nbsp;loi&nbsp;phat&nbsp;sinh<br /> &nbsp; &nbsp; &nbsp; OutputValue&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">vbNullString<br /> &nbsp; &nbsp; &nbsp; Set&nbsp;ExecuteSPWithADOCommand&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; Exit&nbsp;</span><span style="color: #007700">Function<br /></span><span style="color: #0000BB"> &nbsp; <br />ESPResume</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; On&nbsp;Error&nbsp;Resume&nbsp;Next<br /> &nbsp; Set&nbsp;ExecuteSPWithADOCommand&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; Set&nbsp;objCmd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Nothing<br /> &nbsp; CloseDB<br /> &nbsp; Exit&nbsp;</span><span style="color: #007700">Function<br /><br /></span><span style="color: #0000BB">ESPError</span><span style="color: #007700">:<br /></span><span style="color: #0000BB"> &nbsp; ShowErrorMessages&nbsp;Err</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mstrModuleName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ExecuteSPWithADOCommand"<br /></span><span style="color: #0000BB"> &nbsp; Resume&nbsp;ESPResume<br /><br />End&nbsp;</span><span style="color: #007700">Function<br /><br /><br /><br />Public&nbsp;</span><span style="color: #0000BB">Sub&nbsp;ShowErrorMessages</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;StandardErrorObject&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">VBA</span><span style="color: #007700">.</span><span style="color: #0000BB">ErrObject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; ByVal&nbsp;SourceModule&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ByVal&nbsp;SourceMethod&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br /> &nbsp; </span><span style="color: #DD0000">'Su&nbsp;dung&nbsp;cho&nbsp;bay&nbsp;loi&nbsp;cua&nbsp;class.<br /> &nbsp; Dim&nbsp;strMsg&nbsp;As&nbsp;String<br /> &nbsp; &nbsp;<br /> &nbsp; '</span><span style="color: #0000BB">Loi&nbsp;co&nbsp;ban&nbsp;cua&nbsp;he&nbsp;thong</span><span style="color: #007700">.<br /></span><span style="color: #0000BB"> &nbsp; If&nbsp;StandardErrorObject</span><span style="color: #007700">.</span><span style="color: #0000BB">Number&nbsp;</span><span style="color: #007700">&lt;&gt;&nbsp;</span><span style="color: #0000BB">0&nbsp;Then<br /> &nbsp; &nbsp; &nbsp; strMsg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Error:&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">CStr</span><span style="color: #007700">(</span><span style="color: #0000BB">Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Number</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"Description:&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">_<br /> &nbsp; &nbsp; &nbsp; Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Description&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf<br /> &nbsp; End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br /> &nbsp; strMsg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strMsg&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">SourceModule&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #DD0000">"::"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">SourceMethod&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">vbCrLf<br /> &nbsp; &nbsp;<br /> &nbsp; Err</span><span style="color: #007700">.</span><span style="color: #0000BB">Clear<br /> &nbsp; &nbsp;<br /> &nbsp; MsgBoxUni&nbsp;strMsg</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">vbCritical</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Liên&nbsp;h"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7879</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;ng"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">432</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7901</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"i&nbsp;qu"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7843</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"n&nbsp;tr"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7883</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;ch"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">432</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">417</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"ng&nbsp;trình&nbsp;"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">273</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7875</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;tr"&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">ChrW</span><span style="color: #007700">(</span><span style="color: #0000BB">7907</span><span style="color: #007700">)&nbsp;&amp;&nbsp;</span><span style="color: #DD0000">"&nbsp;giúp"<br /></span><span style="color: #0000BB"> &nbsp; &nbsp;<br />End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
<br />
<br />
Link file: <a href="http://www.mediafire.com/file/b28rf1vflxjcwwu/KetNoiSQLServer_ClassADO_Demo.rar" target="_blank" rel="noopener" class="mycode_url">http://www.mediafire.com/file/b28rf1vflx...O_Demo.rar</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[[Video] Hướng dẫn sử dụng Class Modules]]></title>
			<link>https://thuthuataccess.com/forum/thread-9870.html</link>
			<pubDate>Sat, 18 Mar 2017 14:41:37 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=1091">maidinhdan</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-9870.html</guid>
			<description><![CDATA[Bài 1. Giới thiệu về Class Modules trong Access và khai báo biến toàn cục Public<br />
<br />
<div style="text-align: center;" class="mycode_align"><iframe width="560" height="315" src="//www.youtube-nocookie.com/embed/kpuEE18z0Qk" frameborder="0" allowfullscreen="true"></iframe></div>
<br />
<br />
Bài 2. Khai báo Private và kiểm soát các biến khi truyền vào Class<br />
<br />
<div style="text-align: center;" class="mycode_align"><iframe width="560" height="315" src="//www.youtube-nocookie.com/embed/hNVBe4xGQTs" frameborder="0" allowfullscreen="true"></iframe></div>
<br />
<br />
.............Còn tiếp... tối nay làm 2 video thôi<br />
<br />
Demo bài thực hành đính kèm phía dưới<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://thuthuataccess.com/forum/images/attachtypes/zip.gif" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=729" target="_blank" title="">Baithuchanh-Class-bymaidinhdan.zip</a> (Kích cỡ: 49.72 KB / Tải về: 49)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Bài 1. Giới thiệu về Class Modules trong Access và khai báo biến toàn cục Public<br />
<br />
<div style="text-align: center;" class="mycode_align"><iframe width="560" height="315" src="//www.youtube-nocookie.com/embed/kpuEE18z0Qk" frameborder="0" allowfullscreen="true"></iframe></div>
<br />
<br />
Bài 2. Khai báo Private và kiểm soát các biến khi truyền vào Class<br />
<br />
<div style="text-align: center;" class="mycode_align"><iframe width="560" height="315" src="//www.youtube-nocookie.com/embed/hNVBe4xGQTs" frameborder="0" allowfullscreen="true"></iframe></div>
<br />
<br />
.............Còn tiếp... tối nay làm 2 video thôi<br />
<br />
Demo bài thực hành đính kèm phía dưới<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://thuthuataccess.com/forum/images/attachtypes/zip.gif" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=729" target="_blank" title="">Baithuchanh-Class-bymaidinhdan.zip</a> (Kích cỡ: 49.72 KB / Tải về: 49)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Xây dựng Class Modules trong Access ( Cơ bản đến Nâng cao)]]></title>
			<link>https://thuthuataccess.com/forum/thread-9651.html</link>
			<pubDate>Fri, 11 Nov 2016 09:40:58 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=1091">maidinhdan</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-9651.html</guid>
			<description><![CDATA[<span style="color: #339933;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b">Hầu hết các ngôn ngữ lập trình dùng để viết phần mềm ứng dụng nào cũng sử dụng class modules để quản lý dữ liệu, đến đây chúng ta bàn về Access của chúng ta, rất ít bài về chủ đề này. Trên diễn đàn cũng có bài giới thiệu về class của anh Lehongduc, MinhTien... </span></span><br />
<br />
Mở màng bài đầu tiên không phải bài hướng dẫn mà là bài giới thiệu những gì sẽ hiện diện trong chủ đề này<br />
<span style="color: #3366ff;" class="mycode_color"><br />
Và mình rất muốn cùng các bạn cùng thảo luận và trao đổi với các bạn về class cụ thể 5 vấn đề như sau:</span><br />
<span style="color: #ff3333;" class="mycode_color">1. Kinh nghiệm viết class của bản thân<br />
2. Các công cụ hỗ trợ viết class. để viết nhanh nhất ( Trước khi làm gì phải có Đồ nghề trước); nhiều bạn ngại không dùng class vì nó dài dòng, lê thê... nhưng khi có đồ nghề thì chuyện đó nó nhỏ hà.<br />
3. Các Demo bài tập Class từ cơ bản đến nâng cao ( Có video để các bạn dễ theo dõi và trao đổi)<br />
4. Sử dụng đồng thời DAO và ADO thao tác nếu có nhiều thời gian, không thì mình chỉ chọn 1 cái.<br />
5. Class Modules và Modules để giao tiếp với một số kiểu dữ liệu bên ngoài mà không phải là file Access.<br />
6. Tính kế thừa của Class.</span><br />
<span style="color: #ff33ff;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b"><br />
* Rất mong các bạn cùng tham gia chia sẽ, riêng bản thân mình thì 1 tuần sẽ có 1 ca khúc về chủ đề này</span></span><br />
<span style="color: #339933;" class="mycode_color"><br />
Thân ái!</span>]]></description>
			<content:encoded><![CDATA[<span style="color: #339933;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b">Hầu hết các ngôn ngữ lập trình dùng để viết phần mềm ứng dụng nào cũng sử dụng class modules để quản lý dữ liệu, đến đây chúng ta bàn về Access của chúng ta, rất ít bài về chủ đề này. Trên diễn đàn cũng có bài giới thiệu về class của anh Lehongduc, MinhTien... </span></span><br />
<br />
Mở màng bài đầu tiên không phải bài hướng dẫn mà là bài giới thiệu những gì sẽ hiện diện trong chủ đề này<br />
<span style="color: #3366ff;" class="mycode_color"><br />
Và mình rất muốn cùng các bạn cùng thảo luận và trao đổi với các bạn về class cụ thể 5 vấn đề như sau:</span><br />
<span style="color: #ff3333;" class="mycode_color">1. Kinh nghiệm viết class của bản thân<br />
2. Các công cụ hỗ trợ viết class. để viết nhanh nhất ( Trước khi làm gì phải có Đồ nghề trước); nhiều bạn ngại không dùng class vì nó dài dòng, lê thê... nhưng khi có đồ nghề thì chuyện đó nó nhỏ hà.<br />
3. Các Demo bài tập Class từ cơ bản đến nâng cao ( Có video để các bạn dễ theo dõi và trao đổi)<br />
4. Sử dụng đồng thời DAO và ADO thao tác nếu có nhiều thời gian, không thì mình chỉ chọn 1 cái.<br />
5. Class Modules và Modules để giao tiếp với một số kiểu dữ liệu bên ngoài mà không phải là file Access.<br />
6. Tính kế thừa của Class.</span><br />
<span style="color: #ff33ff;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b"><br />
* Rất mong các bạn cùng tham gia chia sẽ, riêng bản thân mình thì 1 tuần sẽ có 1 ca khúc về chủ đề này</span></span><br />
<span style="color: #339933;" class="mycode_color"><br />
Thân ái!</span>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[[Using Class Module] Các phương pháp bổ sung Component vào dự án của bạn]]></title>
			<link>https://thuthuataccess.com/forum/thread-9582.html</link>
			<pubDate>Fri, 07 Oct 2016 13:31:15 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=1091">maidinhdan</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-9582.html</guid>
			<description><![CDATA[Tính làm 1 bài viết về Class Modules để cùng trao đổi và học hỏi thêm về cáh thức tạo và vận hành Class trong VBA Access và tạo ra các thư viên liên kết động *.dll, hay các Ad-In file để làm ứng dụng khác ta lấy ra sử dụng.<br />
<br />
Tình cơ đọc được bài viết này trên GPE cũng hay nên chia sẽ trước<br />
<br />
<br />
<blockquote class="mycode_quote"><cite>Trích dẫn:</cite>Bài viết của anh: <a href="http://www.giaiphapexcel.com/forum/member.php?17-%C4%90%C3%A0o-Vi%E1%BB%87t-C%C6%B0%E1%BB%9Dng" target="_blank" rel="noopener" class="mycode_url"><span style="font-weight: bold;" class="mycode_b"><span style="color: blue;" class="mycode_color"><span style="font-style: italic;" class="mycode_i">[b]Đào Việt Cường</span></span></span>[/b]</a> Cu Tí sành điệu <br />
Chúng ta biết đến chức năng Add-Ins trong MS Excel như một công cụ bổ sung truyền thống. Hầu hết các mục đích bổ sung đều xuất phát từ việc mở rộng nhu cầu ứng dụng. Với các định dạng *.xla, chúng ta có gần như tất cả những gì chúng ta muốn. Chúng ta thường sử dụng cách này vì việc bổ sung và quản lý nó thuận tiện bằng công cụ Add-Ins Manager. Tuy nhiên cách thức bổ sung này bộc lộ một số nhược điểm:<br />
<br />
- Chỉ bổ sung được các tập tin *.xla (Microsoft Excel Add-In file)<br />
- Không tối ưu: một khi add-in được bổ sung vào MSE nó tự động kích hoạt khi trình Excel khởi động ngay cả khi bạn không mở ứng dụng của bạn.<br />
- Không bảo mật: nhiều phần mềm dò tìm mật khẩu có thể phá được password trong *.xla của bạn.<br />
- Tốc độ: do chưa được biên dịch ra ngôn ngữ máy, tốc độ xử lý sẽ thấp hơn (có thể do trình biên dịch phải compile mã chương trình)<br />
- Phân tán và khả năng chia sẻ thấp<br />
<br />
<span style="font-weight: bold;" class="mycode_b">1. Bổ sung các component bằng "con đường Browse":</span><br />
Các bạn đã có dịp tìm hiểu về các về các thành phần cơ bản có trong một dự án VBA. Cũng từ đó, bộ lọc Browser cho các bạn biết các thành phần nào <span style="color: black;" class="mycode_color">có thể được thêm vào dự án của bạn từ bên ngoài:</span><ul class="mycode_list"><li><span style="color: black;" class="mycode_color">Type Libraries(*.olb, *.tlb, *.dll)</span><br />
</li>
<li><span style="color: black;" class="mycode_color">Executable Files</span> (*.exe, *.dll)<br />
</li>
<li>ActiveX Controls (*.ocx)<br />
</li>
</ul>
Hầu hết các component được bổ sung bằng con đường <span style="font-weight: bold;" class="mycode_b">Browse</span> này. Để thấy nhiều hơn, các bạn hãy ấn nút Browse trên hộp thoại References. Để ý đến mục Files of Type mặc định là <span style="font-style: italic;" class="mycode_i">Type Libraries(*.olb, *.tlb, *.dll) </span>các bạn thấy mục đầu tiên là <span style="font-style: italic;" class="mycode_i">Microsoft Office Excel file (*.xls, *.xla). </span>Mục này sẽ cho các bạn nhiều khám phá bất ngờ! Các bạn hãy thực hành và quan sát các hiện tượng xảy ra bên trong dự án của bạn sau khi bổ sung một *.xls hoặc *.xla vào dự án.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">2. Bổ sung các component bằng thủ tục đăng ký hệ thống RegSvr32:</span><br />
Phương pháp này hầu như chỉ áp dụng đối với các thư viện liên kết động (*.dll) hoặc các điều khiển ActiveX (*.ocx). Thủ pháp ở đây là thông qua lệnh Regsvr32 chúng ta có thể để "đăng ký" vào hệ thống các thành phần muốn được bổ sung. Các bạn thực hiện như sau:<ul class="mycode_list"><li>Từ trình đơn RUN của Windows (tại thanh Start) nhập vào các thông tin:<br />
</li>
</ul>
<span style="font-weight: bold;" class="mycode_b">RegSvr32 &lt;App.Path&gt;\&lt;component&gt;</span><br />
Trong đó:<br />
- &lt;component&gt; là tập tin *.dll hoặc *.ocx<br />
- &lt;App.Path&gt; là đường dẫn đến tập tin &lt;component&gt;<ul class="mycode_list"><li>Nếu đăng ký thành công, bạn sẽ nhận được một message thông báo:<br />
</li>
</ul>
DllRegiterServer <span style="font-weight: bold;" class="mycode_b">&lt;App.Path&gt;\&lt;component&gt; </span>succeeded <ul class="mycode_list"><li>Sau khi đăng ký, component sẽ được bổ sung vào danh sách References, các bạn cần mở lại hộp thoại References để đánh dấu chọn component đó trước khi sử dụng<br />
</li>
<li>Nếu bạn muốn gỡ bỏ các đăng ký hãy thêm từ khoá <span style="font-weight: bold;" class="mycode_b">/ u</span> vào sau RegSvr32 như sau:<br />
</li>
</ul>
<span style="font-weight: bold;" class="mycode_b">RegSvr32/ u &lt;App.Path&gt;\&lt;component&gt;</span></blockquote>
<br />
<br />
<div style="text-align: center;" class="mycode_align"><span style="font-weight: bold;" class="mycode_b"> ______________________________________________________________________________________________</span></div>
<span style="font-weight: bold;" class="mycode_b">Nào hãy tiếp tục tìm hiểu 1 số cái cơ bản về <span style="color: #339966;" class="mycode_color">Class Module</span> ( Bài viết được trích từ <a href="http://www.vovisoft.com" target="_blank" rel="noopener" class="mycode_url">http://www.vovisoft.com</a>)</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">1. Sử dụng Class Module</span><br />
 <br />
Class Module là gì ? Là tổng hợp của các bộ phận trong ứng dụng của các bạn.  Gọi tắt là COM ( Component Object Model ).  Phương pháp viết chương trình hiện đại là xử dụng components, một cơ chế trong ứng dụng của các bạn. Như chúng ta biết : Hệ thống viễn thông ngày càng phát triển và đóng một vai trò quan trọng trong đời sống hàng ngày của mọi người trên thế giới. Và trong hệ thống viễn thông, đại đa số, họ xử dụng COM components.  Do đó, trong việc viết chương trình ứng dụng, các bạn không thể thiếu các COM components được.<br />
 <br />
Ứng dụng của các bạn, nếu được tách ra thành từng cơ cấu (components) thì rất dể dàng trong việc phát triển (developement) và giử gìn...Sau đây, chúng tôi sẽ lần lượt giải thích làm sau việc xử dụng Class Module là hữu ích.<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">2. Sử dụng Object và Components</span><br />
COM components, chính nó là bộ phận mang lấy một chức năng nhất định trong ứng dụng.  Chính nó cũng là một ứng dụng, cũng có code, methodes, functions và được hoán chuyển thành .dll, .bas,..., và từ đó, nó được xử dụng như COM.<br />
 <br />
Dưới đây là hình ảnh cho thấy các bạn có thể tạo thành một component và cùng một lúc có thể tạo thành 2 instances lúc run time<br />
 <br />
<div style="text-align: center;" class="mycode_align"><img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chuong3ab.gif" loading="lazy"  alt="[Hình: chuong3ab.gif]" class="mycode_img" /></div>
 <br />
Khi bạn đã có Components rồi, bạn có thể lấy từ trong dự án của bạn hay là dự án ở ngoài... đều xử dụng được hết.   <br />
 <br />
<span style="font-weight: bold;" class="mycode_b">3. Những lợi ích khi xử dụng Components</span><br />
 <br />
<span style="font-weight: bold;" class="mycode_b">*Sử dụng nhiều lần </span>: Khi các bạn tạo thành cho mình một bộ phận trong ứng dụng rồi (component) thì bộ phận đó sẽ được xử dụng nhiều lần.  Hoặc trong ứng dụng của bạn nhưng ở trong những form khác chẳng hạn...Hay là những người trong nhóm phát triển ứng dụng vẫn có thể xử dụng component đó...<br />
Chỉ cần bạn bỏ bộ phận đó trong kho nhu liệu là bạn có thể xử dụng bất cứ lúc nào.  Với Object browser, bạn có thể gọi component đó và xử dụng nhiều lần.<br />
<span style="font-weight: bold;" class="mycode_b">*Làm giảm bớt sự phức tạp :</span> Những người làm việc cùng nhóm với bạn sẽ không mất nhiều thời gian và công sức khi tìm hiểu những chức năng từng bộ phận trong phương trình ứng dụng.<br />
<span style="font-weight: bold;" class="mycode_b">*Dể dàng trong việc sửa đổi :</span> Khi cần thay đổi phương trình ứng dụng, các bạn không cần phải tốn nhiều thời gian và tránh được rất nhiều bugs khi nâng cấp ứng dụng...<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b"> Class Module là gì ?</span> Bài viết lấy hình ảnh trên VB6<br />
 <br />
Các bạn muốn có một COM component trong ứng dụng của mình, chuyện đầu tiên là các bạn phải có một class module trong ứng dụng của bạn trước.  Rối sau đó, các bạn có thể xử dụng bộ phận COM đó trong suốt quá trình hoàn chỉnh ứng dụng hay cho các vay mượn tùy theo yêu cầu của chương trình.<br />
 <br />
Class Module, đơn giản là một loại Visual Basic code module.  Ðược viết dưới dạng *.cls và tương tợ như *.bas , Khác biệt ở chổ là Class Module bao gồm chức năng (funtion) mà chức năng này có thể xử dụng ở những form khác trong cùng một ứng dụng.  Mỗi một class module ứng cho một bộ phận trong ứng dụng và các bạn có thể có vài thể loại class module trong ứng dụng của mình.<br />
 <br />
Ðể xử dụng class module, các bạn phải làm cho nó một instance, rồi sau đó thông qua instance đó, mà các properties, methods, events của nó để rồi hoàn thành một cái class cho ứng dụng.<br />
 <br />
Thí dụ điển hình là như vầy : <br />
 <br />
Muốn có một Employee class mà nó có properties là : Lastname, Firstname.  Method là hired. Bạn phải làm một instance cho Employee object.  Rồi sau đó, muốn tìm chi tiết về các nhân viên bất cứ ở đâu trong ứng dụng, chúng ta chỉ cần xử dụng Employee class module mà thôi.<br />
 <br />
Chương 3_Phần 2_Ðoạn 1 : Xử dụng Class Builder<br />
 <br />
Ðể dể dàng cho việc tạo thành Class, Visual Basic có một công cụ gọi là Class Builder.  Nó tự động làm cho bạn một số việc và chuyện của các bạn là điền vào chi tiết mà thôi.  Ðây là công cụ để tạo thành Class : <span style="color: #339933;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b">( Trước đây mình cũng post 1 bài trên diễn đàn tool hỗ trợ viết Class này)</span></span><br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chuong3a1.gif" loading="lazy"  alt="[Hình: chuong3a1.gif]" class="mycode_img" /></div>
<br />
Sau đây là những phần mà Class Builder bao gồm :<br />
Property Builder<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp1.gif" loading="lazy"  alt="[Hình: vb6chp1.gif]" class="mycode_img" /><br />
Method Builder<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp2.gif" loading="lazy"  alt="[Hình: vb6chp2.gif]" class="mycode_img" /><br />
Event Builder<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp3.gif" loading="lazy"  alt="[Hình: vb6chp3.gif]" class="mycode_img" /><br />
Attributes<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp4.gif" loading="lazy"  alt="[Hình: vb6chp4.gif]" class="mycode_img" /><br />
Chương 3_Phần 2_Ðoạn 2 : Class Module Events<br />
 <br />
Ðể tạo dể dàng cho các bạn viết ứng dụng, Visual Basic đã viết sẳn cho các bạn 2 events.  Ðó là initialize và terminate<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Initialize event :</span> Nhất định các bạn phải kiểm soát các nhu liệu hay tài liệu cần thiết cho ứng dụng của mình, do đó, initialize event là event đầu tiên mình phải xử dụng.  Sau đây là các hàng code :<br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;Class_Initialize&nbsp;</span><span style="color: #007700">()<br /></span><span style="color: #DD0000">'Initialize&nbsp;Data<br /> iDept&nbsp;=&nbsp;5<br /> End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Terminate event :</span> Dùng để chấm dứt công việc.  Sau đây là các hàng code <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB"> Private&nbsp;Sub&nbsp;Class_Terminate</span><span style="color: #007700">()<br /></span><span style="color: #0000BB"> </span><span style="color: #DD0000">'Any&nbsp;termination&nbsp;code<br /> End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Và dỉ nhiên các bạn có thể thêm vào nhiều event nữa tùy theo yêu cầu của người xử dụng.<br />
 <br />
Chương 3_Phần 2_Ðoạn 2 : Adding Component information and Help<br />
 <br />
Vì có nhiều classes trong ứng dụng, cho nên để dể dàng trong việc xử dụng, chúng ta cần phải thêm vào các chi tiết nói về chức năng của class đó.  Và mỗi khi mủi chuột chỉ đến đâu thì những lời giải thích về chức năng đó hiện ra.  Theo các bước sau đây thì các bạn có thể thêm vào các lời giải thích :<br />
 <br />
  Nhìn vào hình ảnh dưới đây, chúng ta sẽ thấy làm sao để điền thêm chi tiết vào bộ phận Class<br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chap3a2.gif" loading="lazy"  alt="[Hình: chap3a2.gif]" class="mycode_img" /></div>
<br />
Chương 3 _Phần 2_Ðoạn 4 : Xử dụng Object Browser<br />
 <br />
Ðể nhận xét một cách tổng quát một class trong ứng dụng, hãy xử dụng Oject Browser.  Object Browser trong Visual Basic là một công cụ dùng để nhìn xem các properties, methods, events chứa đựng trong một class.  Trên View menu, bấm trên Object Browser, các bạn sẽ có một Object Browser.  Theo các bước trên, các bạn sẽ có được :<br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chap3a5.gif" loading="lazy"  alt="[Hình: chap3a5.gif]" class="mycode_img" /></div>
Có 2 bản danh sách cho thấy project có bao nhiêu classes?  Trong class có bao nhiêu members ?...Và Object Browser cho chúng ta nhìn biết các bộ phận tron ứng dụng dể dàng hơn.<br />
 <br />
Chương 3 _Phần 3 _Ðoạn 1 : Tạo thành Property<br />
 <br />
Property xác định nhu liệu hay chức năng của một class.  Thí dụ như một class Employee có thể có các properties như <span style="font-weight: bold;" class="mycode_b">FirstName, LastName, HireDate…</span>Các bạn có thể xác định  property trong ứng dụng của mình bằng 2 cách :<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Sử dụng Public Variables :</span> Các bạn không cần phải viết code khi property được hình thành, bạn chỉ cần xác định Public variable để giử nhu liệu mà thôi.  Thí dụ như sau<br />
 <br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">FirstName&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp;<br /></span></code></div></div></div> <br />
Sử dụng Property Procedure : Dùng cách này nếu các bạn muốn viết code khi hình thành property.  Với property procedure, các bạn có thể làm những việc sau đây :<br />
 <br />
    Tiến hành procedure khi các dử kiện của property được xác định<br />
    Làm cho property có một chức năng nhất định như giao trả một nhu liệu giới hạn nào đó.<br />
    Không cho phép property thay đổi.<br />
 <br />
Property procedure có 3 phần : Set, Let, Get.  Khi hình thành property procedure, các bạn xác định theo từng cặp, thí dụ như : Set và Get, Let và Get.  Bởi vì lý do giản dị là property set hay let phải được tiến hành trước, rồi sau đó, procedure get mới có thể cung cấp nhu liệu mà procedure Set hay Let xác định.  Như thí dụ điển hình sau đây :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;FirstName</span><span style="color: #007700">(</span><span style="color: #0000BB">passedName&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">                       &nbsp;mvarFirstName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Ucase</span><span style="color: #007700">(</span><span style="color: #0000BB">passedName</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;FirstName</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br />                       &nbsp;FirstName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarFirstName<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
 <br />
Sử dụng default Property : Theo những bước sau đây các bạn sẽ xác định được default property<br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chap3a7.gif" loading="lazy"  alt="[Hình: chap3a7.gif]" class="mycode_img" /></div>
 <br />
Chương 3_Phần 3_Ðoạn 2 : Tạo thành Methods<br />
 <br />
Methods đại diện cho một chức năng trong ứng dụng của bạn mà class bao gồm.  Thí dụ như class Employee có 2 methods là Hire và PayIncrease.  Ðể tạo thành method cho một bộ phận trong ứng dụng, bạn chỉ cần tạo thành Public Sub hay là Function procedure trong class module đó.<br />
 <br />
Sau đây là thí dụ làm sao để tạo thành một method là thêm dữ kiện vào trong kho nhu liệu :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">Hire</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /> &nbsp; &nbsp; &nbsp; &nbsp;‘&nbsp;add&nbsp;employee&nbsp;record&nbsp;to&nbsp;database&nbsp;here<br /> MsgBox&nbsp;“Employee&nbsp;was&nbsp;added&nbsp;to&nbsp;the&nbsp;Database”<br />           &nbsp;‘&nbsp;</span><span style="color: #007700">if&nbsp;</span><span style="color: #0000BB">successful<br /> Hire&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br />End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Sau đây là thí dụ để tạo thành method tăng lương cho nhân viên :<br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">PayIncrease&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">dPercent &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Double</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Integer<br />           &nbsp;mvarSalary&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarSalary&nbsp;</span><span style="color: #007700">*&nbsp;(</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">dPercent</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Function &nbsp;<br /></span></code></div></div></div><br />
 <br />
Chương 3_Phần 3_Ðoạn 3 : Xử dụng Named Constants<br />
 <br />
Khi các bạn xử dụng cách thay thế (variables) thì trong suốt quá trình ứng dụng tiến hành, variables sẽ giao trả cho bạn nhiều nhu liệu chứa trong Database (Kho nhu liệu).  Nhưng với Named Constants (thay thế bằng cách đặt tên), các bạn sẽ có lợi điểm là Named Constant chỉ giao trả một nhu liệu nhất định mà thôi.  Thí dụ như trong trường hợp phải xài 2 nút Yes và No cho một lựa chọn, bạn chỉ cần xài Named Constant là vbYesNo mà thôi.<br />
 <br />
Tạo thành Named Constants : Ðơn giản như chúng ta xử dụng variable vậy.  Sau đây là thí dụ làm sao để có Named Constant tên là JobLevel<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Enum&nbsp;JobLevel<br />         &nbsp;jExecutive&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br />         &nbsp;jManagement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br />         &nbsp;jStaff&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br />End&nbsp;Enum&nbsp;<br /></span></code></div></div></div><br />
 <br />
Với Named Constant này, bạn có thể thêm method vào trong class module của mình.  Như method xem cấp bậc việc làm của nhân viên như sau :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Sub&nbsp;CheckExecutiveStatus</span><span style="color: #007700">(</span><span style="color: #0000BB">iLevel&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">JobLevel<br />           &nbsp;</span><span style="color: #007700">If&nbsp;</span><span style="color: #0000BB">iLevel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">jExecutive&nbsp;Then<br />                       &nbsp;MsgBox&nbsp;“Executive&nbsp;Level&nbsp;Status&nbsp;Approved”<br />           &nbsp;</span><span style="color: #007700">Else<br /></span><span style="color: #0000BB">                       &nbsp;MsgBox&nbsp;“Executive&nbsp;Status&nbsp;Denied”<br />           &nbsp;End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB">End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Xử dụng Enumerations (cách xếp thứ tự bằng số) như là Property value : Các bạn đã có Named  Constant, các bạn cũng đã biết property value đi theo từng cặp Set và Get hay là Let và Get...Thì để xác định một chứ năng giao trả một dử kiện nhất định cho class module của mình, phương pháp hữu hiệu nhất là xử dụng Enumerations Property value.  Thí dụ bạn xáx định một property có tên là ActiveJobLevel thì hãy theo những bước sau đây :<br />
 <br />
Private mvarJobLevel As JobLevel<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;ActiveJobLevel&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">jl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">JobLevel</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">           &nbsp;mvarJobLevel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">jl<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;ActiveJobLevel&nbsp;</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">JobLevel<br />           &nbsp;ActiveJobLevel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarJobLevel<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
 <br />
Chương 3_Phần 3_Ðoạn 4 : Thêm Events vào trong Class Module<br />
 <br />
Trước đó chúng ta đã biết Visual Basic có sẳn 2 events là Initialize và Terminate.  Và chúng ta cũng có thể thêm events vào trong class của mình tùy theo yêu cầu.  Thí dụ như chúng ta có một component gọi là COrder.  Chúng ta có thể dựng nên một event gọi là Status khi COrder tiến hành.  Theo 2 bước sau đây, chúng ta có thể thêm events vào trong class :<br />
 <br />
<span style="font-weight: bold;" class="mycode_b"><span style="color: #339933;" class="mycode_color">    DeClare the event      (Nhận định the event)</span></span><br />
<span style="font-weight: bold;" class="mycode_b"><span style="color: #339933;" class="mycode_color">    Raise the event          (Dựng lên the event)</span></span><br />
 <br />
Nhận định event : Xử dụng keyword là Event để nhận định.  Chẳng hạn như :<br />
 <br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Event&nbsp;Status</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;StatusText&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)&nbsp;<br /></span></code></div></div></div> <br />
Dựng lên event : Xử dụng RaiseEvent statement để dựng lên event.  Chẳng hạn như :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Sub&nbsp;SubmitOrder</span><span style="color: #007700">()<br /></span><span style="color: #0000BB">         &nbsp;‘code&nbsp;to&nbsp;submit&nbsp;an&nbsp;order&nbsp;goes&nbsp;here<br />         &nbsp;RaiseEvent&nbsp;Status&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">“Checking&nbsp;Credit</span><span style="color: #007700">...</span><span style="color: #0000BB">”</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">         &nbsp;‘code&nbsp;to&nbsp;check&nbsp;the&nbsp;credit&nbsp;goes&nbsp;here<br />         &nbsp;RaiseEvent&nbsp;Status&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">“Processing&nbsp;Order</span><span style="color: #007700">...</span><span style="color: #0000BB">”</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">         &nbsp;‘code&nbsp;to&nbsp;process&nbsp;an&nbsp;order&nbsp;goes&nbsp;her<br />End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Những liên hệ khác với component : Khi nhận định Event, chúng ta có thể xử dụng ByVal (by value) hay ByRef (by reference).  Do đó tùy theo trường hợp nhận định event mà chúng ta dựng event lên. Nếu ByRef, chúng ta phải làm sao để class có thể trao đổi nhu liệu và event được tiến hành.  Chẳng hạn như thí dụ sau đây :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">Dim&nbsp;iLimit&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Integer<br />iLimit&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">400<br />‘raise&nbsp;the&nbsp;event&nbsp;to&nbsp;be&nbsp;handled&nbsp;by&nbsp;the&nbsp;client<br />RaiseEvent&nbsp;LimitChanged</span><span style="color: #007700">(</span><span style="color: #0000BB">iLimit</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">‘now&nbsp;check&nbsp;to&nbsp;see&nbsp;</span><span style="color: #007700">if&nbsp;</span><span style="color: #0000BB">the&nbsp;client&nbsp;changed&nbsp;the&nbsp;limit<br /></span><span style="color: #007700">If&nbsp;</span><span style="color: #0000BB">iLimit&nbsp;</span><span style="color: #007700">&lt;&gt;&nbsp;</span><span style="color: #0000BB">400&nbsp;Then<br />‘client&nbsp;did&nbsp;not&nbsp;accept&nbsp;the&nbsp;</span><span style="color: #007700">new&nbsp;</span><span style="color: #0000BB">limit<br />End&nbsp;</span><span style="color: #007700">If&nbsp;<br /></span></code></div></div></div><br />
Ai còn bài nào giới thiệu lên tiếp nhé]]></description>
			<content:encoded><![CDATA[Tính làm 1 bài viết về Class Modules để cùng trao đổi và học hỏi thêm về cáh thức tạo và vận hành Class trong VBA Access và tạo ra các thư viên liên kết động *.dll, hay các Ad-In file để làm ứng dụng khác ta lấy ra sử dụng.<br />
<br />
Tình cơ đọc được bài viết này trên GPE cũng hay nên chia sẽ trước<br />
<br />
<br />
<blockquote class="mycode_quote"><cite>Trích dẫn:</cite>Bài viết của anh: <a href="http://www.giaiphapexcel.com/forum/member.php?17-%C4%90%C3%A0o-Vi%E1%BB%87t-C%C6%B0%E1%BB%9Dng" target="_blank" rel="noopener" class="mycode_url"><span style="font-weight: bold;" class="mycode_b"><span style="color: blue;" class="mycode_color"><span style="font-style: italic;" class="mycode_i">[b]Đào Việt Cường</span></span></span>[/b]</a> Cu Tí sành điệu <br />
Chúng ta biết đến chức năng Add-Ins trong MS Excel như một công cụ bổ sung truyền thống. Hầu hết các mục đích bổ sung đều xuất phát từ việc mở rộng nhu cầu ứng dụng. Với các định dạng *.xla, chúng ta có gần như tất cả những gì chúng ta muốn. Chúng ta thường sử dụng cách này vì việc bổ sung và quản lý nó thuận tiện bằng công cụ Add-Ins Manager. Tuy nhiên cách thức bổ sung này bộc lộ một số nhược điểm:<br />
<br />
- Chỉ bổ sung được các tập tin *.xla (Microsoft Excel Add-In file)<br />
- Không tối ưu: một khi add-in được bổ sung vào MSE nó tự động kích hoạt khi trình Excel khởi động ngay cả khi bạn không mở ứng dụng của bạn.<br />
- Không bảo mật: nhiều phần mềm dò tìm mật khẩu có thể phá được password trong *.xla của bạn.<br />
- Tốc độ: do chưa được biên dịch ra ngôn ngữ máy, tốc độ xử lý sẽ thấp hơn (có thể do trình biên dịch phải compile mã chương trình)<br />
- Phân tán và khả năng chia sẻ thấp<br />
<br />
<span style="font-weight: bold;" class="mycode_b">1. Bổ sung các component bằng "con đường Browse":</span><br />
Các bạn đã có dịp tìm hiểu về các về các thành phần cơ bản có trong một dự án VBA. Cũng từ đó, bộ lọc Browser cho các bạn biết các thành phần nào <span style="color: black;" class="mycode_color">có thể được thêm vào dự án của bạn từ bên ngoài:</span><ul class="mycode_list"><li><span style="color: black;" class="mycode_color">Type Libraries(*.olb, *.tlb, *.dll)</span><br />
</li>
<li><span style="color: black;" class="mycode_color">Executable Files</span> (*.exe, *.dll)<br />
</li>
<li>ActiveX Controls (*.ocx)<br />
</li>
</ul>
Hầu hết các component được bổ sung bằng con đường <span style="font-weight: bold;" class="mycode_b">Browse</span> này. Để thấy nhiều hơn, các bạn hãy ấn nút Browse trên hộp thoại References. Để ý đến mục Files of Type mặc định là <span style="font-style: italic;" class="mycode_i">Type Libraries(*.olb, *.tlb, *.dll) </span>các bạn thấy mục đầu tiên là <span style="font-style: italic;" class="mycode_i">Microsoft Office Excel file (*.xls, *.xla). </span>Mục này sẽ cho các bạn nhiều khám phá bất ngờ! Các bạn hãy thực hành và quan sát các hiện tượng xảy ra bên trong dự án của bạn sau khi bổ sung một *.xls hoặc *.xla vào dự án.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">2. Bổ sung các component bằng thủ tục đăng ký hệ thống RegSvr32:</span><br />
Phương pháp này hầu như chỉ áp dụng đối với các thư viện liên kết động (*.dll) hoặc các điều khiển ActiveX (*.ocx). Thủ pháp ở đây là thông qua lệnh Regsvr32 chúng ta có thể để "đăng ký" vào hệ thống các thành phần muốn được bổ sung. Các bạn thực hiện như sau:<ul class="mycode_list"><li>Từ trình đơn RUN của Windows (tại thanh Start) nhập vào các thông tin:<br />
</li>
</ul>
<span style="font-weight: bold;" class="mycode_b">RegSvr32 &lt;App.Path&gt;\&lt;component&gt;</span><br />
Trong đó:<br />
- &lt;component&gt; là tập tin *.dll hoặc *.ocx<br />
- &lt;App.Path&gt; là đường dẫn đến tập tin &lt;component&gt;<ul class="mycode_list"><li>Nếu đăng ký thành công, bạn sẽ nhận được một message thông báo:<br />
</li>
</ul>
DllRegiterServer <span style="font-weight: bold;" class="mycode_b">&lt;App.Path&gt;\&lt;component&gt; </span>succeeded <ul class="mycode_list"><li>Sau khi đăng ký, component sẽ được bổ sung vào danh sách References, các bạn cần mở lại hộp thoại References để đánh dấu chọn component đó trước khi sử dụng<br />
</li>
<li>Nếu bạn muốn gỡ bỏ các đăng ký hãy thêm từ khoá <span style="font-weight: bold;" class="mycode_b">/ u</span> vào sau RegSvr32 như sau:<br />
</li>
</ul>
<span style="font-weight: bold;" class="mycode_b">RegSvr32/ u &lt;App.Path&gt;\&lt;component&gt;</span></blockquote>
<br />
<br />
<div style="text-align: center;" class="mycode_align"><span style="font-weight: bold;" class="mycode_b"> ______________________________________________________________________________________________</span></div>
<span style="font-weight: bold;" class="mycode_b">Nào hãy tiếp tục tìm hiểu 1 số cái cơ bản về <span style="color: #339966;" class="mycode_color">Class Module</span> ( Bài viết được trích từ <a href="http://www.vovisoft.com" target="_blank" rel="noopener" class="mycode_url">http://www.vovisoft.com</a>)</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">1. Sử dụng Class Module</span><br />
 <br />
Class Module là gì ? Là tổng hợp của các bộ phận trong ứng dụng của các bạn.  Gọi tắt là COM ( Component Object Model ).  Phương pháp viết chương trình hiện đại là xử dụng components, một cơ chế trong ứng dụng của các bạn. Như chúng ta biết : Hệ thống viễn thông ngày càng phát triển và đóng một vai trò quan trọng trong đời sống hàng ngày của mọi người trên thế giới. Và trong hệ thống viễn thông, đại đa số, họ xử dụng COM components.  Do đó, trong việc viết chương trình ứng dụng, các bạn không thể thiếu các COM components được.<br />
 <br />
Ứng dụng của các bạn, nếu được tách ra thành từng cơ cấu (components) thì rất dể dàng trong việc phát triển (developement) và giử gìn...Sau đây, chúng tôi sẽ lần lượt giải thích làm sau việc xử dụng Class Module là hữu ích.<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">2. Sử dụng Object và Components</span><br />
COM components, chính nó là bộ phận mang lấy một chức năng nhất định trong ứng dụng.  Chính nó cũng là một ứng dụng, cũng có code, methodes, functions và được hoán chuyển thành .dll, .bas,..., và từ đó, nó được xử dụng như COM.<br />
 <br />
Dưới đây là hình ảnh cho thấy các bạn có thể tạo thành một component và cùng một lúc có thể tạo thành 2 instances lúc run time<br />
 <br />
<div style="text-align: center;" class="mycode_align"><img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chuong3ab.gif" loading="lazy"  alt="[Hình: chuong3ab.gif]" class="mycode_img" /></div>
 <br />
Khi bạn đã có Components rồi, bạn có thể lấy từ trong dự án của bạn hay là dự án ở ngoài... đều xử dụng được hết.   <br />
 <br />
<span style="font-weight: bold;" class="mycode_b">3. Những lợi ích khi xử dụng Components</span><br />
 <br />
<span style="font-weight: bold;" class="mycode_b">*Sử dụng nhiều lần </span>: Khi các bạn tạo thành cho mình một bộ phận trong ứng dụng rồi (component) thì bộ phận đó sẽ được xử dụng nhiều lần.  Hoặc trong ứng dụng của bạn nhưng ở trong những form khác chẳng hạn...Hay là những người trong nhóm phát triển ứng dụng vẫn có thể xử dụng component đó...<br />
Chỉ cần bạn bỏ bộ phận đó trong kho nhu liệu là bạn có thể xử dụng bất cứ lúc nào.  Với Object browser, bạn có thể gọi component đó và xử dụng nhiều lần.<br />
<span style="font-weight: bold;" class="mycode_b">*Làm giảm bớt sự phức tạp :</span> Những người làm việc cùng nhóm với bạn sẽ không mất nhiều thời gian và công sức khi tìm hiểu những chức năng từng bộ phận trong phương trình ứng dụng.<br />
<span style="font-weight: bold;" class="mycode_b">*Dể dàng trong việc sửa đổi :</span> Khi cần thay đổi phương trình ứng dụng, các bạn không cần phải tốn nhiều thời gian và tránh được rất nhiều bugs khi nâng cấp ứng dụng...<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b"> Class Module là gì ?</span> Bài viết lấy hình ảnh trên VB6<br />
 <br />
Các bạn muốn có một COM component trong ứng dụng của mình, chuyện đầu tiên là các bạn phải có một class module trong ứng dụng của bạn trước.  Rối sau đó, các bạn có thể xử dụng bộ phận COM đó trong suốt quá trình hoàn chỉnh ứng dụng hay cho các vay mượn tùy theo yêu cầu của chương trình.<br />
 <br />
Class Module, đơn giản là một loại Visual Basic code module.  Ðược viết dưới dạng *.cls và tương tợ như *.bas , Khác biệt ở chổ là Class Module bao gồm chức năng (funtion) mà chức năng này có thể xử dụng ở những form khác trong cùng một ứng dụng.  Mỗi một class module ứng cho một bộ phận trong ứng dụng và các bạn có thể có vài thể loại class module trong ứng dụng của mình.<br />
 <br />
Ðể xử dụng class module, các bạn phải làm cho nó một instance, rồi sau đó thông qua instance đó, mà các properties, methods, events của nó để rồi hoàn thành một cái class cho ứng dụng.<br />
 <br />
Thí dụ điển hình là như vầy : <br />
 <br />
Muốn có một Employee class mà nó có properties là : Lastname, Firstname.  Method là hired. Bạn phải làm một instance cho Employee object.  Rồi sau đó, muốn tìm chi tiết về các nhân viên bất cứ ở đâu trong ứng dụng, chúng ta chỉ cần xử dụng Employee class module mà thôi.<br />
 <br />
Chương 3_Phần 2_Ðoạn 1 : Xử dụng Class Builder<br />
 <br />
Ðể dể dàng cho việc tạo thành Class, Visual Basic có một công cụ gọi là Class Builder.  Nó tự động làm cho bạn một số việc và chuyện của các bạn là điền vào chi tiết mà thôi.  Ðây là công cụ để tạo thành Class : <span style="color: #339933;" class="mycode_color"><span style="font-weight: bold;" class="mycode_b">( Trước đây mình cũng post 1 bài trên diễn đàn tool hỗ trợ viết Class này)</span></span><br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chuong3a1.gif" loading="lazy"  alt="[Hình: chuong3a1.gif]" class="mycode_img" /></div>
<br />
Sau đây là những phần mà Class Builder bao gồm :<br />
Property Builder<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp1.gif" loading="lazy"  alt="[Hình: vb6chp1.gif]" class="mycode_img" /><br />
Method Builder<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp2.gif" loading="lazy"  alt="[Hình: vb6chp2.gif]" class="mycode_img" /><br />
Event Builder<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp3.gif" loading="lazy"  alt="[Hình: vb6chp3.gif]" class="mycode_img" /><br />
Attributes<br />
 <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/vb6chp4.gif" loading="lazy"  alt="[Hình: vb6chp4.gif]" class="mycode_img" /><br />
Chương 3_Phần 2_Ðoạn 2 : Class Module Events<br />
 <br />
Ðể tạo dể dàng cho các bạn viết ứng dụng, Visual Basic đã viết sẳn cho các bạn 2 events.  Ðó là initialize và terminate<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Initialize event :</span> Nhất định các bạn phải kiểm soát các nhu liệu hay tài liệu cần thiết cho ứng dụng của mình, do đó, initialize event là event đầu tiên mình phải xử dụng.  Sau đây là các hàng code :<br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Private&nbsp;</span><span style="color: #0000BB">Sub&nbsp;Class_Initialize&nbsp;</span><span style="color: #007700">()<br /></span><span style="color: #DD0000">'Initialize&nbsp;Data<br /> iDept&nbsp;=&nbsp;5<br /> End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Terminate event :</span> Dùng để chấm dứt công việc.  Sau đây là các hàng code <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB"> Private&nbsp;Sub&nbsp;Class_Terminate</span><span style="color: #007700">()<br /></span><span style="color: #0000BB"> </span><span style="color: #DD0000">'Any&nbsp;termination&nbsp;code<br /> End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Và dỉ nhiên các bạn có thể thêm vào nhiều event nữa tùy theo yêu cầu của người xử dụng.<br />
 <br />
Chương 3_Phần 2_Ðoạn 2 : Adding Component information and Help<br />
 <br />
Vì có nhiều classes trong ứng dụng, cho nên để dể dàng trong việc xử dụng, chúng ta cần phải thêm vào các chi tiết nói về chức năng của class đó.  Và mỗi khi mủi chuột chỉ đến đâu thì những lời giải thích về chức năng đó hiện ra.  Theo các bước sau đây thì các bạn có thể thêm vào các lời giải thích :<br />
 <br />
  Nhìn vào hình ảnh dưới đây, chúng ta sẽ thấy làm sao để điền thêm chi tiết vào bộ phận Class<br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chap3a2.gif" loading="lazy"  alt="[Hình: chap3a2.gif]" class="mycode_img" /></div>
<br />
Chương 3 _Phần 2_Ðoạn 4 : Xử dụng Object Browser<br />
 <br />
Ðể nhận xét một cách tổng quát một class trong ứng dụng, hãy xử dụng Oject Browser.  Object Browser trong Visual Basic là một công cụ dùng để nhìn xem các properties, methods, events chứa đựng trong một class.  Trên View menu, bấm trên Object Browser, các bạn sẽ có một Object Browser.  Theo các bước trên, các bạn sẽ có được :<br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chap3a5.gif" loading="lazy"  alt="[Hình: chap3a5.gif]" class="mycode_img" /></div>
Có 2 bản danh sách cho thấy project có bao nhiêu classes?  Trong class có bao nhiêu members ?...Và Object Browser cho chúng ta nhìn biết các bộ phận tron ứng dụng dể dàng hơn.<br />
 <br />
Chương 3 _Phần 3 _Ðoạn 1 : Tạo thành Property<br />
 <br />
Property xác định nhu liệu hay chức năng của một class.  Thí dụ như một class Employee có thể có các properties như <span style="font-weight: bold;" class="mycode_b">FirstName, LastName, HireDate…</span>Các bạn có thể xác định  property trong ứng dụng của mình bằng 2 cách :<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Sử dụng Public Variables :</span> Các bạn không cần phải viết code khi property được hình thành, bạn chỉ cần xác định Public variable để giử nhu liệu mà thôi.  Thí dụ như sau<br />
 <br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">FirstName&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String&nbsp;<br /></span></code></div></div></div> <br />
Sử dụng Property Procedure : Dùng cách này nếu các bạn muốn viết code khi hình thành property.  Với property procedure, các bạn có thể làm những việc sau đây :<br />
 <br />
    Tiến hành procedure khi các dử kiện của property được xác định<br />
    Làm cho property có một chức năng nhất định như giao trả một nhu liệu giới hạn nào đó.<br />
    Không cho phép property thay đổi.<br />
 <br />
Property procedure có 3 phần : Set, Let, Get.  Khi hình thành property procedure, các bạn xác định theo từng cặp, thí dụ như : Set và Get, Let và Get.  Bởi vì lý do giản dị là property set hay let phải được tiến hành trước, rồi sau đó, procedure get mới có thể cung cấp nhu liệu mà procedure Set hay Let xác định.  Như thí dụ điển hình sau đây :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;FirstName</span><span style="color: #007700">(</span><span style="color: #0000BB">passedName&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">                       &nbsp;mvarFirstName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Ucase</span><span style="color: #007700">(</span><span style="color: #0000BB">passedName</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;FirstName</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">String<br />                       &nbsp;FirstName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarFirstName<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
 <br />
Sử dụng default Property : Theo những bước sau đây các bạn sẽ xác định được default property<br />
<div style="text-align: center;" class="mycode_align"> <img src="http://www.vovisoft.com/vovisoft/tutorials/vb6course/images/chap3a7.gif" loading="lazy"  alt="[Hình: chap3a7.gif]" class="mycode_img" /></div>
 <br />
Chương 3_Phần 3_Ðoạn 2 : Tạo thành Methods<br />
 <br />
Methods đại diện cho một chức năng trong ứng dụng của bạn mà class bao gồm.  Thí dụ như class Employee có 2 methods là Hire và PayIncrease.  Ðể tạo thành method cho một bộ phận trong ứng dụng, bạn chỉ cần tạo thành Public Sub hay là Function procedure trong class module đó.<br />
 <br />
Sau đây là thí dụ làm sao để tạo thành một method là thêm dữ kiện vào trong kho nhu liệu :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">Hire</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">Boolean<br /> &nbsp; &nbsp; &nbsp; &nbsp;‘&nbsp;add&nbsp;employee&nbsp;record&nbsp;to&nbsp;database&nbsp;here<br /> MsgBox&nbsp;“Employee&nbsp;was&nbsp;added&nbsp;to&nbsp;the&nbsp;Database”<br />           &nbsp;‘&nbsp;</span><span style="color: #007700">if&nbsp;</span><span style="color: #0000BB">successful<br /> Hire&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">True<br />End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Sau đây là thí dụ để tạo thành method tăng lương cho nhân viên :<br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;Function&nbsp;</span><span style="color: #0000BB">PayIncrease&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">dPercent &nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Double</span><span style="color: #007700">)&nbsp;As&nbsp;</span><span style="color: #0000BB">Integer<br />           &nbsp;mvarSalary&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarSalary&nbsp;</span><span style="color: #007700">*&nbsp;(</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">dPercent</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">End&nbsp;Function &nbsp;<br /></span></code></div></div></div><br />
 <br />
Chương 3_Phần 3_Ðoạn 3 : Xử dụng Named Constants<br />
 <br />
Khi các bạn xử dụng cách thay thế (variables) thì trong suốt quá trình ứng dụng tiến hành, variables sẽ giao trả cho bạn nhiều nhu liệu chứa trong Database (Kho nhu liệu).  Nhưng với Named Constants (thay thế bằng cách đặt tên), các bạn sẽ có lợi điểm là Named Constant chỉ giao trả một nhu liệu nhất định mà thôi.  Thí dụ như trong trường hợp phải xài 2 nút Yes và No cho một lựa chọn, bạn chỉ cần xài Named Constant là vbYesNo mà thôi.<br />
 <br />
Tạo thành Named Constants : Ðơn giản như chúng ta xử dụng variable vậy.  Sau đây là thí dụ làm sao để có Named Constant tên là JobLevel<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Enum&nbsp;JobLevel<br />         &nbsp;jExecutive&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1<br />         &nbsp;jManagement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2<br />         &nbsp;jStaff&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3<br />End&nbsp;Enum&nbsp;<br /></span></code></div></div></div><br />
 <br />
Với Named Constant này, bạn có thể thêm method vào trong class module của mình.  Như method xem cấp bậc việc làm của nhân viên như sau :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Sub&nbsp;CheckExecutiveStatus</span><span style="color: #007700">(</span><span style="color: #0000BB">iLevel&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">JobLevel<br />           &nbsp;</span><span style="color: #007700">If&nbsp;</span><span style="color: #0000BB">iLevel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">jExecutive&nbsp;Then<br />                       &nbsp;MsgBox&nbsp;“Executive&nbsp;Level&nbsp;Status&nbsp;Approved”<br />           &nbsp;</span><span style="color: #007700">Else<br /></span><span style="color: #0000BB">                       &nbsp;MsgBox&nbsp;“Executive&nbsp;Status&nbsp;Denied”<br />           &nbsp;End&nbsp;</span><span style="color: #007700">If<br /></span><span style="color: #0000BB">End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Xử dụng Enumerations (cách xếp thứ tự bằng số) như là Property value : Các bạn đã có Named  Constant, các bạn cũng đã biết property value đi theo từng cặp Set và Get hay là Let và Get...Thì để xác định một chứ năng giao trả một dử kiện nhất định cho class module của mình, phương pháp hữu hiệu nhất là xử dụng Enumerations Property value.  Thí dụ bạn xáx định một property có tên là ActiveJobLevel thì hãy theo những bước sau đây :<br />
 <br />
Private mvarJobLevel As JobLevel<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Let&nbsp;ActiveJobLevel&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">jl&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">JobLevel</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">           &nbsp;mvarJobLevel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">jl<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Property&nbsp;Get&nbsp;ActiveJobLevel&nbsp;</span><span style="color: #007700">()&nbsp;As&nbsp;</span><span style="color: #0000BB">JobLevel<br />           &nbsp;ActiveJobLevel&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mvarJobLevel<br />End&nbsp;Property&nbsp;<br /></span></code></div></div></div><br />
 <br />
Chương 3_Phần 3_Ðoạn 4 : Thêm Events vào trong Class Module<br />
 <br />
Trước đó chúng ta đã biết Visual Basic có sẳn 2 events là Initialize và Terminate.  Và chúng ta cũng có thể thêm events vào trong class của mình tùy theo yêu cầu.  Thí dụ như chúng ta có một component gọi là COrder.  Chúng ta có thể dựng nên một event gọi là Status khi COrder tiến hành.  Theo 2 bước sau đây, chúng ta có thể thêm events vào trong class :<br />
 <br />
<span style="font-weight: bold;" class="mycode_b"><span style="color: #339933;" class="mycode_color">    DeClare the event      (Nhận định the event)</span></span><br />
<span style="font-weight: bold;" class="mycode_b"><span style="color: #339933;" class="mycode_color">    Raise the event          (Dựng lên the event)</span></span><br />
 <br />
Nhận định event : Xử dụng keyword là Event để nhận định.  Chẳng hạn như :<br />
 <br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Event&nbsp;Status</span><span style="color: #007700">(</span><span style="color: #0000BB">ByVal&nbsp;StatusText&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">String</span><span style="color: #007700">)&nbsp;<br /></span></code></div></div></div> <br />
Dựng lên event : Xử dụng RaiseEvent statement để dựng lên event.  Chẳng hạn như :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #007700">Public&nbsp;</span><span style="color: #0000BB">Sub&nbsp;SubmitOrder</span><span style="color: #007700">()<br /></span><span style="color: #0000BB">         &nbsp;‘code&nbsp;to&nbsp;submit&nbsp;an&nbsp;order&nbsp;goes&nbsp;here<br />         &nbsp;RaiseEvent&nbsp;Status&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">“Checking&nbsp;Credit</span><span style="color: #007700">...</span><span style="color: #0000BB">”</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">         &nbsp;‘code&nbsp;to&nbsp;check&nbsp;the&nbsp;credit&nbsp;goes&nbsp;here<br />         &nbsp;RaiseEvent&nbsp;Status&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">“Processing&nbsp;Order</span><span style="color: #007700">...</span><span style="color: #0000BB">”</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">         &nbsp;‘code&nbsp;to&nbsp;process&nbsp;an&nbsp;order&nbsp;goes&nbsp;her<br />End&nbsp;Sub&nbsp;<br /></span></code></div></div></div><br />
 <br />
Những liên hệ khác với component : Khi nhận định Event, chúng ta có thể xử dụng ByVal (by value) hay ByRef (by reference).  Do đó tùy theo trường hợp nhận định event mà chúng ta dựng event lên. Nếu ByRef, chúng ta phải làm sao để class có thể trao đổi nhu liệu và event được tiến hành.  Chẳng hạn như thí dụ sau đây :<br />
 <br />
<br />
<div class="codeblock phpcodeblock"><div class="title">Mã PHP:</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">Dim&nbsp;iLimit&nbsp;</span><span style="color: #007700">As&nbsp;</span><span style="color: #0000BB">Integer<br />iLimit&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">400<br />‘raise&nbsp;the&nbsp;event&nbsp;to&nbsp;be&nbsp;handled&nbsp;by&nbsp;the&nbsp;client<br />RaiseEvent&nbsp;LimitChanged</span><span style="color: #007700">(</span><span style="color: #0000BB">iLimit</span><span style="color: #007700">)<br /></span><span style="color: #0000BB">‘now&nbsp;check&nbsp;to&nbsp;see&nbsp;</span><span style="color: #007700">if&nbsp;</span><span style="color: #0000BB">the&nbsp;client&nbsp;changed&nbsp;the&nbsp;limit<br /></span><span style="color: #007700">If&nbsp;</span><span style="color: #0000BB">iLimit&nbsp;</span><span style="color: #007700">&lt;&gt;&nbsp;</span><span style="color: #0000BB">400&nbsp;Then<br />‘client&nbsp;did&nbsp;not&nbsp;accept&nbsp;the&nbsp;</span><span style="color: #007700">new&nbsp;</span><span style="color: #0000BB">limit<br />End&nbsp;</span><span style="color: #007700">If&nbsp;<br /></span></code></div></div></div><br />
Ai còn bài nào giới thiệu lên tiếp nhé]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Sử dụng Class Module trong lập trình Access]]></title>
			<link>https://thuthuataccess.com/forum/thread-6311.html</link>
			<pubDate>Sun, 12 May 2013 08:05:07 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=10002">Minh Tiên</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-6311.html</guid>
			<description><![CDATA[Kính gửi các: Acc có nhu cầu.<br />
     Mình tìm trên diễn đàn nhưng không thầy hướng dẫn hay Demo sử dụng Class trong Access, mình đã tìm tham khảo tại địa chỉ: <a href="http://www.di-mgt.com.au/cl_Simple.html" target="_blank" rel="noopener" class="mycode_url">http://www.di-mgt.com.au/cl_Simple.html</a> và mình đã áp dụng OK cho "Tiện ích của mình.<br />
Nay xin chia sẽ cho các Acc có nhu cầu. Do mình tìm trên diễn đàn chưa có nên mạo muội lập Chủ đề mới. Xin BQL thông cảm nếu CT đã có.<br />
<a href="http://www.mediafire.com/?64qn8dndnvgr7rl" target="_blank" rel="noopener" class="mycode_url">Demo</a>]]></description>
			<content:encoded><![CDATA[Kính gửi các: Acc có nhu cầu.<br />
     Mình tìm trên diễn đàn nhưng không thầy hướng dẫn hay Demo sử dụng Class trong Access, mình đã tìm tham khảo tại địa chỉ: <a href="http://www.di-mgt.com.au/cl_Simple.html" target="_blank" rel="noopener" class="mycode_url">http://www.di-mgt.com.au/cl_Simple.html</a> và mình đã áp dụng OK cho "Tiện ích của mình.<br />
Nay xin chia sẽ cho các Acc có nhu cầu. Do mình tìm trên diễn đàn chưa có nên mạo muội lập Chủ đề mới. Xin BQL thông cảm nếu CT đã có.<br />
<a href="http://www.mediafire.com/?64qn8dndnvgr7rl" target="_blank" rel="noopener" class="mycode_url">Demo</a>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Sử dụng Class Module và Kết nối dữ liệu SQL SERVER trong Access VBA]]></title>
			<link>https://thuthuataccess.com/forum/thread-5297.html</link>
			<pubDate>Wed, 20 Jun 2012 10:51:02 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://thuthuataccess.com/forum/member.php?action=profile&uid=5232">lehongduc</a>]]></dc:creator>
			<guid isPermaLink="false">https://thuthuataccess.com/forum/thread-5297.html</guid>
			<description><![CDATA[Chào các Bạn,<br />
<br />
Hôm nay tôi muốn trao đổi với các Bạn về vấn đề "Sử dụng Class Module và Kết nối dữ liệu SQL SERVER trong Access VBA" như một giải pháp tối ưu cho các ứng dụng được thiết kế với VBA trong Microsoft Access. Trao đổi này có đính kèm file nguồn để làm ví dụ minh họa.<br />
<br />
Để lấy một ví dụ cụ thể, ở đây giả định ta có nhu cầu thiết kế 1 ứng dụng Microsoft Access dùng để quản lý 1 danh bạ điện thoại.<br />
<br />
Ứng dụng của chúng ta sẽ bao gồm 1 file dữ liệu và 1 file ứng dụng. Các Bạn có thể tạo File dữ liệu bằng Microsoft Access hoặc SQL SERVER. Ở đây tôi tạo file dữ liệu bằng SQL SERVER.<br />
File dữ liệu đã được nạp trên 15.000 mẫu tin.<br />
Khi file ứng dụng được nạp, ta sẽ cho kết nối với file dữ liệu bằng thủ tục Log-In.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Mục đích của tôi thông qua cách thiết kế trên nhằm:</span><br />
+ minh họa khả năng của Access VBA có thể lập trình theo hướng đối tượng;<br />
+ kết nối được với nguồn dữ liệu ngoài, ở đây là nguồn SQL SERVER;<br />
+ có thể tạo được những Unbound Form nhằm đáp ứng nhu cầu truy xuất dữ liệu với nhiều người dùng qua mạng máy tính, đồng thời cải thiện được tốc độ xử lý dữ liệu.<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Về Cấu trúc của file dữ liệu:</span><br />
Với ứng dụng này ta chỉ cần có 1 file dữ liệu với 1 bảng dữ liệu. Tất nhiên các Bạn có thể tùy biến thêm nếu thấy cần.<br />
- Tôi đặt tên file dữ liệu này là danhba<br />
- Và tạo 1 bảng dữ liệu có tên là tblDanhsach, với các cột dữ liệu như sau:<br />
+ Ten: tên của 1 người cụ thể trong danh bạ, kiểu dữ liệu Text<br />
+ HoChulot: họ và chữ lót, kiểu dữ liệu Text<br />
+ Gioitinh: xác định giới tính, kiểu dữ liệu Yes/No (mặc định là Nam, với giá trị là True)<br />
+ Ngaysinh: ngày sinh, kiểu dữ liệu Date<br />
+ Dtdd: số điện thoại di động, kiểu dữ liệu Text<br />
+ Dtnha: số điện thoại ở nhà riêng, kiểu dữ liệu Text<br />
+ Dtvp: số điện thoại ở văn phòng làm việc, kiểu dữ liệu Text<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Với ứng dụng làm ví dụ sẽ cho ta biết cách:</span><br />
1. Kết nối với nguồn dữ liệu bên ngoài MS. Access, ở đây là SQL SERVER<br />
2. Viết 1 Class module như thế nào<br />
3. Tạo 1 Unbound Form và gắn kết dữ liệu trên đó như thế nào<br />
<br />
Trong bài sau tôi sẽ trình bày tiếp vào nội dung chính của chuyên đề này.<br />
Rất mong các Bạn cùng tham gia nghiên cứu và trao đổi.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Nội dung các file đính kèm:</span><br />
1. File ứng dụng MS. Access với định dạng mdb có mã nguồn<br />
2. File SQL (Text) dùng để tạo database trên SQL SERVER cục bộ (local) nếu các Bạn muốn tạo.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Cũng xin trao đổi rõ thêm</span>: File ứng dụng và file dữ liệu nêu trên mới chỉ là "sườn" còn "thô", để nó trở thành 1 ứng dụng hoàn chỉnh, chúng ta còn phải tinh chỉnh nhiều thứ; đó cũng chính là công việc mà tôi muốn mời các Bạn cùng tham gia trao đổi, qua đó chúng ta thu hoạch được những kiến thức căn bản chắc chắn hơn về chuyên đề này.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Tài liệu tham khảo</span>:<br />
Tài liệu tôi dùng để tham khảo chính để viết loạt bài này (bao gồm ứng dụng làm ví dụ) là loạt sách:<br />
Beginning Access 2003 VBA, Beginning Access 2007 VBA <br />
của Denise M. Gosnell<br />
<hr class="mycode_hr" />
Chào các Bạn,<br />
Xin nói thêm về chuyện ứng dụng và dữ liệu còn "thô":<br />
<br />
Nói chúng "thô" bởi lẽ:<br />
<br />
1. File dữ liệu SQL SERVER chỉ mới có các bảng dữ liệu thôi. Như vậy chúng chỉ mới là chỗ để lưu dữ liệu phát sinh, chưa làm được việc xử lý dữ liệu (ta dễ thấy một phần những việc đơn giản trong việc xử lý dữ liệu này như: lưu, xóa, trích xuất thông tin, lọc thông tin). <br />
Bản thân SQL SERVER là 1 hệ thống quản trị cơ sở dữ liệu mạnh, chứ không chỉ đơn thuần là nơi để lưu dữ liệu. Ta sẽ bàn tới cách giao nhiệm vụ xử lý dữ liệu cho cái file dữ liệu SQL SERVER đã tạo ở trên. Hiện nay việc xử lý dữ liệu vẫn còn do file ứng dụng đãm trách thông qua các câu lệnh SQL trong các module.<br />
<br />
2. Nếu chạy file ứng dụng đang có ta sẽ thấy khi mở Form "frmContact" (dùng để cập nhật và xem dữ liệu) sẽ còn mất 1 ít thời gian mà ta có thể cảm nhận được. Mục tiêu của chúng ta là phải làm sao cho nhanh đến mức không cảm thấy phải chờ một chút nào.<br />
Tôi đã kiểm tra thử mở form nói trên với kết nối internet qua 1 USB 3G của Viettel (loại 7.2 Mbps) trên xe hơi đang chạy: thời gian nạp xong form mất khoảng 25 giây.<br />
<br />
Có Bạn nào tìm được lý do nào khác không?<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Link tải File ứng dụng minh họa, bản cập nhật ngày 15/7/2014:</span><br />
<a href="http://www.mediafire.com/download/j5v854t46ozo5ck/qldanhba_150714.rar" target="_blank" rel="noopener" class="mycode_url">http://www.mediafire.com/download/j5v854...150714.rar</a><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://thuthuataccess.com/forum/images/attachtypes/zip.gif" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=423" target="_blank" title="">CreateDanhbaDB.zip</a> (Kích cỡ: 1.12 KB / Tải về: 436)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://thuthuataccess.com/forum/images/attachtypes/zip.gif" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=424" target="_blank" title="">qldanhba.zip</a> (Kích cỡ: 54.47 KB / Tải về: 436)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Chào các Bạn,<br />
<br />
Hôm nay tôi muốn trao đổi với các Bạn về vấn đề "Sử dụng Class Module và Kết nối dữ liệu SQL SERVER trong Access VBA" như một giải pháp tối ưu cho các ứng dụng được thiết kế với VBA trong Microsoft Access. Trao đổi này có đính kèm file nguồn để làm ví dụ minh họa.<br />
<br />
Để lấy một ví dụ cụ thể, ở đây giả định ta có nhu cầu thiết kế 1 ứng dụng Microsoft Access dùng để quản lý 1 danh bạ điện thoại.<br />
<br />
Ứng dụng của chúng ta sẽ bao gồm 1 file dữ liệu và 1 file ứng dụng. Các Bạn có thể tạo File dữ liệu bằng Microsoft Access hoặc SQL SERVER. Ở đây tôi tạo file dữ liệu bằng SQL SERVER.<br />
File dữ liệu đã được nạp trên 15.000 mẫu tin.<br />
Khi file ứng dụng được nạp, ta sẽ cho kết nối với file dữ liệu bằng thủ tục Log-In.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Mục đích của tôi thông qua cách thiết kế trên nhằm:</span><br />
+ minh họa khả năng của Access VBA có thể lập trình theo hướng đối tượng;<br />
+ kết nối được với nguồn dữ liệu ngoài, ở đây là nguồn SQL SERVER;<br />
+ có thể tạo được những Unbound Form nhằm đáp ứng nhu cầu truy xuất dữ liệu với nhiều người dùng qua mạng máy tính, đồng thời cải thiện được tốc độ xử lý dữ liệu.<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Về Cấu trúc của file dữ liệu:</span><br />
Với ứng dụng này ta chỉ cần có 1 file dữ liệu với 1 bảng dữ liệu. Tất nhiên các Bạn có thể tùy biến thêm nếu thấy cần.<br />
- Tôi đặt tên file dữ liệu này là danhba<br />
- Và tạo 1 bảng dữ liệu có tên là tblDanhsach, với các cột dữ liệu như sau:<br />
+ Ten: tên của 1 người cụ thể trong danh bạ, kiểu dữ liệu Text<br />
+ HoChulot: họ và chữ lót, kiểu dữ liệu Text<br />
+ Gioitinh: xác định giới tính, kiểu dữ liệu Yes/No (mặc định là Nam, với giá trị là True)<br />
+ Ngaysinh: ngày sinh, kiểu dữ liệu Date<br />
+ Dtdd: số điện thoại di động, kiểu dữ liệu Text<br />
+ Dtnha: số điện thoại ở nhà riêng, kiểu dữ liệu Text<br />
+ Dtvp: số điện thoại ở văn phòng làm việc, kiểu dữ liệu Text<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Với ứng dụng làm ví dụ sẽ cho ta biết cách:</span><br />
1. Kết nối với nguồn dữ liệu bên ngoài MS. Access, ở đây là SQL SERVER<br />
2. Viết 1 Class module như thế nào<br />
3. Tạo 1 Unbound Form và gắn kết dữ liệu trên đó như thế nào<br />
<br />
Trong bài sau tôi sẽ trình bày tiếp vào nội dung chính của chuyên đề này.<br />
Rất mong các Bạn cùng tham gia nghiên cứu và trao đổi.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Nội dung các file đính kèm:</span><br />
1. File ứng dụng MS. Access với định dạng mdb có mã nguồn<br />
2. File SQL (Text) dùng để tạo database trên SQL SERVER cục bộ (local) nếu các Bạn muốn tạo.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Cũng xin trao đổi rõ thêm</span>: File ứng dụng và file dữ liệu nêu trên mới chỉ là "sườn" còn "thô", để nó trở thành 1 ứng dụng hoàn chỉnh, chúng ta còn phải tinh chỉnh nhiều thứ; đó cũng chính là công việc mà tôi muốn mời các Bạn cùng tham gia trao đổi, qua đó chúng ta thu hoạch được những kiến thức căn bản chắc chắn hơn về chuyên đề này.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Tài liệu tham khảo</span>:<br />
Tài liệu tôi dùng để tham khảo chính để viết loạt bài này (bao gồm ứng dụng làm ví dụ) là loạt sách:<br />
Beginning Access 2003 VBA, Beginning Access 2007 VBA <br />
của Denise M. Gosnell<br />
<hr class="mycode_hr" />
Chào các Bạn,<br />
Xin nói thêm về chuyện ứng dụng và dữ liệu còn "thô":<br />
<br />
Nói chúng "thô" bởi lẽ:<br />
<br />
1. File dữ liệu SQL SERVER chỉ mới có các bảng dữ liệu thôi. Như vậy chúng chỉ mới là chỗ để lưu dữ liệu phát sinh, chưa làm được việc xử lý dữ liệu (ta dễ thấy một phần những việc đơn giản trong việc xử lý dữ liệu này như: lưu, xóa, trích xuất thông tin, lọc thông tin). <br />
Bản thân SQL SERVER là 1 hệ thống quản trị cơ sở dữ liệu mạnh, chứ không chỉ đơn thuần là nơi để lưu dữ liệu. Ta sẽ bàn tới cách giao nhiệm vụ xử lý dữ liệu cho cái file dữ liệu SQL SERVER đã tạo ở trên. Hiện nay việc xử lý dữ liệu vẫn còn do file ứng dụng đãm trách thông qua các câu lệnh SQL trong các module.<br />
<br />
2. Nếu chạy file ứng dụng đang có ta sẽ thấy khi mở Form "frmContact" (dùng để cập nhật và xem dữ liệu) sẽ còn mất 1 ít thời gian mà ta có thể cảm nhận được. Mục tiêu của chúng ta là phải làm sao cho nhanh đến mức không cảm thấy phải chờ một chút nào.<br />
Tôi đã kiểm tra thử mở form nói trên với kết nối internet qua 1 USB 3G của Viettel (loại 7.2 Mbps) trên xe hơi đang chạy: thời gian nạp xong form mất khoảng 25 giây.<br />
<br />
Có Bạn nào tìm được lý do nào khác không?<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Link tải File ứng dụng minh họa, bản cập nhật ngày 15/7/2014:</span><br />
<a href="http://www.mediafire.com/download/j5v854t46ozo5ck/qldanhba_150714.rar" target="_blank" rel="noopener" class="mycode_url">http://www.mediafire.com/download/j5v854...150714.rar</a><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://thuthuataccess.com/forum/images/attachtypes/zip.gif" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=423" target="_blank" title="">CreateDanhbaDB.zip</a> (Kích cỡ: 1.12 KB / Tải về: 436)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://thuthuataccess.com/forum/images/attachtypes/zip.gif" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=424" target="_blank" title="">qldanhba.zip</a> (Kích cỡ: 54.47 KB / Tải về: 436)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
	</channel>
</rss>