Я использую Ms-Access в качестве внешнего интерфейса и mysql в качестве внутреннего. я отобразил данные из списка mysql i, мне нужно отредактировать данные в самом списке.
Есть ли другой способ, которым я могу редактировать данные.
Я пробовал несколько способов, которыми могуНе могу найти.
Заранее благодарен.
Нужна ваша помощь.
Форма в списке прикрепила изображение, которое я отображал в виде списка
Option Compare Database
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmdtext As New ADODB.Command
Private Sub cmd_extract_Click()
Dim strfield As String
Dim strextract As String
Dim intItemsInList As Integer
Dim intCounter As Integer
Dim intRow As Integer
Dim intCol As Integer
intItemsInList = Me![lstbox].ListCount
For intCounter = 0 To intItemsInList - 1
Me![lstbox].RemoveItem 0
Next
strfield = Me.cmb1
If strfield = "ALL" Then
strextract = "SELECT *FROM emp_details JOIN dept_details ON emp_details.E_Dept = dept_details.D_Name ORDER BY Emp_Id ASC;"
Set cmdtext.ActiveConnection = cn
cmdtext.CommandType = adCmdText
cmdtext.CommandText = strextract
Set rs = cmdtext.Execute
Me.lstbox.AddItem ("EMP-ID" & ";" & "EMP-NAME" & ";" & "EMP-DEPT" & ";" & "EMP-SALARY" & ";" & "DEPT_ID" & ";" & "DEPT_NAME" & ";" & "DEPT_HEAD")
If (rs.RecordCount <> 0) Then
Do While Not rs.EOF
With Me.lstbox
.AddItem (rs.Fields(0) & ";" & rs.Fields(1) & ";" & rs.Fields(2) & ";" & rs.Fields(3) & ";" & rs.Fields(4) & ";" & rs.Fields(5) & ";" & rs.Fields(6))
.ColumnHeads = True
rs.MoveNext
End With
Loop
End If
Else
strextract = "SELECT * FROM emp_details JOIN dept_details ON emp_details.E_Dept = dept_details.D_Name WHERE dept_details.D_Name = '" & strfield & "';"
Set cmdtext.ActiveConnection = cn
cmdtext.CommandType = adCmdText
cmdtext.CommandText = strextract
Set rs = cmdtext.Execute
'Me.lstbox.RowSourceType = "Value List"
Me.lstbox.AddItem ("EMP-ID" & ";" & "EMP-NAME" & ";" & "EMP-DEPT" & ";" & "EMP-SALARY" & ";" & "DEPT_ID" & ";" & "DEPT_NAME" & ";" & "DEPT_HEAD")
If (rs.RecordCount <> 0) Then
Do While Not rs.EOF
With Me.lstbox
.AddItem (rs.Fields(0) & ";" & rs.Fields(1) & ";" & rs.Fields(2) & ";" & rs.Fields(3) & ";" & rs.Fields(4) & ";" & rs.Fields(5) & ";" & rs.Fields(6))
.ColumnHeads = True
rs.MoveNext
End With
Loop
End If
End If
End Sub
Public Sub Form_Load()
Dim cnnstring As String
cnnstring = "Driver={MySQL ODBC 8.0 UNICODE Driver};Server=localhost;Database=My_Project2;Uid=root;Pwd=password;"
If cn.State = 0 Then
cn.Open cnnstring
End If
Dim cquery As String
cquery = "SELECT * FROM dept_details;"
'FULL OUTER JOIN dept_details ON emp_details.E-Dept = dept_details.D_NAME
With rs
Set .ActiveConnection = cn
.Source = cquery
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
rs.MoveFirst
With Me.cmb1
.AddItem "ALL"
Do
cmb1.AddItem rs!D_Name
rs.MoveNext
Loop Until rs.EOF
End With
rs.Close
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim cnnstring As String
cnnstring = "Driver={MySQL ODBC 8.0 UNICODE Driver};Server=localhost;Database=My_Project2;Uid=root;Pwd=password;"
cn.Open cnnstring
Dim cquery As String
cquery = "SELECT * FROM dept_details;"
'FULL OUTER JOIN dept_details ON emp_details.E-Dept = dept_details.D_NAME
With rs
Set .ActiveConnection = cn
.Source = cquery
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
rs.MoveFirst
With Me.cmb1
.AddItem "ALL"
Do
cmb1.AddItem rs!D_Name
rs.MoveNext
Loop Until rs.EOF
End With
rs.Close
End Sub
Private Sub lstbox_DblClick(Cancel As Integer)
'If cn.State = 1 Then
'cn.Close
'End If
Dim listid As Long
listid = Me.lstbox.Value
DoCmd.Close acForm, "Form_Form3"
DoCmd.OpenForm "Form4", OpenArgs:=listid
End Sub