ต้องการให้ใส่ User Name และ Password เมื่อเปิดโปรแกรม
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 837   3
URL.หัวข้อ / URL
ต้องการให้ใส่ User Name และ Password เมื่อเปิดโปรแกรม

ผมได้ Link database กับ SQL 7 เมื่อเวลาเปิดโปรแกรมขึ้นจะขึ้น Form ให้เราใส่ User name และ password เสมอ ทำอย่างไรได้บ้างครับ เพื่อให้สามารถใส่ User name และ password เองเมื่อเวลาเปิดโปรแกรมขึ้นมาเลยครับ

3 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R01162
ใช้เวอร์ชันไหนอยู่ครับ ถ้าเป็น 2000 หรือสูงกว่า จะมี Wizard ช่ยยในการ Link ข้อมูลกับ SQL Server ให้ เมื่อเราใน User Name และ Password แล้วมันจะไม่ถามหาอีกครับ หรือจะเปิดตอนที่ต้องการเท่านั้นก็ได้ เช่นในฟอร์มเป้าหมาย ให้ connect กับ SQL Server เมื่อเปิดเท่านั้น และปิดตอนที่ออกจากฟอร์มเป้าหมาย ลองใช้โค้ดนี้ดูครับ Private Sub Form_Open(Cancel As Integer) Dim cnn As New ADODB.Connection Dim rst As New ADODB.Recordset cnn.Open "Provider=SQLOLEDB;Data Source=Acer3;User ID=Sa; " & _ " Password=;Initial Catalog=Pubs " With rst .Source = "Select * from Employee" .CursorType = adOpenForwardOnly .LockType = adLockReadOnly .ActiveConnection = cnn .CursorLocation = adUseClient .Open End With 'Set the form's Recordset property to the ADO recordset Set Me.Recordset = rst Set rst = Nothing Set cnn = Nothing End Sub Private Sub Form_Unload(Cancel As Integer) 'Close the ADO connection we opened Dim cnn As ADODB.Connection Set cnn = Me.Recordset.ActiveConnection cnn.Close Set cnn = Nothing End Sub
2 @R01174
ผมลองทดสอบที่ access 2000 ปรากฎตามที่อาจารย์แนะนำครับ
3 @R01198
วันนี้ผมไปเจอคำถามคล้ายๆ กันนี้ที่ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_2000&Number=156689&page=0&view=collapsed&sb=5&o=7&fpart=&vc=1&PHPSESSID= เขาทำเหมือนที่ผมได้แนะนำไว้ข้างบน แต่เขาให้วน Loop ด้วย MoveNext จึงทำให้เขาเห็นแค่ข้อมูลสุดท้าย และเขาปิด Recordset ทันที โค้ดที่เขามีปัญหามีดังนี้ Dim conn As New ADODB.Connection Dim cmd As New ADODB.Command Dim rs As New ADODB.Recordset Set con = New ADODB.Connection con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WINDOWS\Desktop\IP_Test\Trev_DB.mdb;Persist Security Info=false" con.Open Set rs1 = New ADODB.Recordset sys = [Forms]![CRYPTO_Main]![Site_List] Dim vstrCommand As String vstrCommand = "SELECT * from AssetChecker where Site =" & "'" & sys & "'" Me.RecordSource = vstrCommand 'Call rs1.Open("SELECT * from AssetChecker where Site =" & "'" & sys & "'", con) x = 1 Do While Not rs1.EOF aa = rs1.Fields(1).Value bb = rs1.Fields(2).Value x = x + 1 rs1.MoveNext Loop rs1.Close con.Close ผมแก้ให้เขาไปดังนี้ครับ Private Sub Form_Open(Cancel As Integer) Dim conn As New ADODB.Connection Dim cmd As New ADODB.Command Dim rs1 As New ADODB.Recordset Set con = New ADODB.Connection con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WINDOWS\Desktop\IP_Test\Trev_DB.mdb;Persist Security Info=false" con.Open Set rs1 = New ADODB.Recordset sys = [Forms]![CRYPTO_Main]![Site_List] Dim vstrCommand As String vstrCommand = "SELECT * from AssetChecker where Site =" & "'" & sys & "'" rs1.Open(vstrCommand, con) Me.Recordset = vstrCommand aa = rs1.Fields(1).Value bb = rs1.Fields(2).Value ' DO NOT CLOSE the rs1 here Set rs1 = Nothing Set con = Nothing End Sub Private Sub Form_Unload(Cancel As Integer) 'Close the ADO connection we opened Dim conn As ADODB.Connection Set con = Me.Recordset.ActiveConnection con.Close Set con = Nothing End Sub
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0560s