D
DracKewl
Hey All,
This is what I need to do.
1. Load a list box using ADO.
2. I do not want the recordset to be associated to the form. With my
present routine I have to associate it so I can delete items.
3. For simplistic purposes I want the recordset deleted from the list as it
is picked, I do not what that recordset deleted from the datasource.
I'm connecting to postgreSQL database. My intention is that when a selected
item is removed from the list, I will take one of the field values from the
recordset and pass it into a stored procedure and let the backend delete the
record for me.
So far I can delete items as long as they are not the first record;
otherwise the whole form goes blank. The other thing I noticed is that the
rs.RecordCount returns zero once one record is deleted even though there are
many.
The other thing is that I’m not sure that filtering out the record is the
best approach before deleting. But it’s the only way I can get it to remove
the record.
Here is my code. It’s pretty simple.
Option Compare Database
Option Explicit
Private conn As New ADODB.Connection
Private rs As New ADODB.Recordset
Private Sub cmdLoadBox_Click()
' Initializaition
Set conn = New ADODB.Connection
conn.Open "DRIVER={PostgreSQL
Unicode};SERVER=localhost;port=5432;DATABASE=PDM_Dev;UID=postgres;PWD=ajberlyn;"
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = conn
.LockType = adLockBatchOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.Open "SELECT * FROM customer", options:=adCmdText
.ActiveConnection = Nothing
End With
'Add recordsets to Listbox
With List0
.RowSourceType = "Table/Query"
.ColumnCount = rs.Fields.Count
.ColumnHeads = True
End With
Set List0.Recordset = rs ' Assign data into the listbox
Set Me.Recordset = rs ' Assign RS as the recordset for the form
conn.Close
End Sub
Private Sub List0_Click()
' Delete the record that matches the selection
rs.Filter = "CUSTOMER_ID = '" & Me![List0] & "'"
rs.Delete
End Sub
This is what I need to do.
1. Load a list box using ADO.
2. I do not want the recordset to be associated to the form. With my
present routine I have to associate it so I can delete items.
3. For simplistic purposes I want the recordset deleted from the list as it
is picked, I do not what that recordset deleted from the datasource.
I'm connecting to postgreSQL database. My intention is that when a selected
item is removed from the list, I will take one of the field values from the
recordset and pass it into a stored procedure and let the backend delete the
record for me.
So far I can delete items as long as they are not the first record;
otherwise the whole form goes blank. The other thing I noticed is that the
rs.RecordCount returns zero once one record is deleted even though there are
many.
The other thing is that I’m not sure that filtering out the record is the
best approach before deleting. But it’s the only way I can get it to remove
the record.
Here is my code. It’s pretty simple.
Option Compare Database
Option Explicit
Private conn As New ADODB.Connection
Private rs As New ADODB.Recordset
Private Sub cmdLoadBox_Click()
' Initializaition
Set conn = New ADODB.Connection
conn.Open "DRIVER={PostgreSQL
Unicode};SERVER=localhost;port=5432;DATABASE=PDM_Dev;UID=postgres;PWD=ajberlyn;"
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = conn
.LockType = adLockBatchOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.Open "SELECT * FROM customer", options:=adCmdText
.ActiveConnection = Nothing
End With
'Add recordsets to Listbox
With List0
.RowSourceType = "Table/Query"
.ColumnCount = rs.Fields.Count
.ColumnHeads = True
End With
Set List0.Recordset = rs ' Assign data into the listbox
Set Me.Recordset = rs ' Assign RS as the recordset for the form
conn.Close
End Sub
Private Sub List0_Click()
' Delete the record that matches the selection
rs.Filter = "CUSTOMER_ID = '" & Me![List0] & "'"
rs.Delete
End Sub