Advertisement

02.06.2008 at 07:53AM PST, ID: 23141569
[x]
Attachment Details

Using VBA to edit record and delete records

Asked by Dan89 in Access Coding/Macros

Tags: Microsoft, Access, 2007

I have table (supplier) which simply combines two primary keys from two other tables Contacts and Items, supplier uses the primary key from items as its own primary key. In a certain form there are two list boxes and an option box with 3 radio buttons. The 3 options are, Do nothing, Change to another free item and delete item. The first list box uses a query to show all items that are currently attached to the contact which is in question (as a contact can have more than one different item) from the supplier table.  The other list box runs a similar query that compares the items in the supplier table and those that are in the items table, and displays those that are not in supplier. These are free items and are awaiting to be combined with a contact in the supplier table. When the first and third options are selected the second list box is disabled, when  the second option is selected the second list box is enabled. What I want to happen is the user selects an option from the first list box, then choose an option, should that be option 1, nothing should happen. When option 2 is selected, the itemID from the first list box is replaced by that in the second list box. When the third option is selected the record selected in the first list box should be deleted. These events are triggered by a button click. I am currently using the code shown to achieve this, nothing happens to any records although there is no errors. Any suggestions?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
Private Sub btnSaveChange_Click()
Select Case Me!FrameOptions
Case 1
DoCmd.Close
 
Case 2
    If [LstItems].Value <> 0 Then
    
        Dim OldItems As New ADODB.Recordset
    
        OldItems.Open "Supplier", CurrentProject.Connection, _
            CursorType:=adOpenKeyset, LockType:=adLockBatchOptimistic
            
        Do While Not OldItems.EOF
            If OldItems("ItemID") = [LstItems].Value Then
                OldItems("ItemID") = [lstFreeItems].Value
                OldItems.Update
            End If
            OldItems.MoveNext
        Loop
    Else
        MsgBox ("No items are assigned to this contact")
    End If
    DoCmd.Close
Case 3
    Dim Items As New ADODB.Recordset
    
    Items.Open "Supplier", CurrentProject.Connection, _
        CursorType:=adOpenKeyset, LockType:=adLockBatchOptimistic
        
    Do While Not Items.EOF
        If Items("ItemID") = [LstItems].Value Then
            Items.Delete
            Items.Update
        End If
        Items.MoveNext
    Loop
    DoCmd.Close
End Select
End Sub
 
 
[+][-]02.06.2008 at 08:01AM PST, ID: 20833052

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 08:19AM PST, ID: 20833244

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 08:26AM PST, ID: 20833305

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 08:38AM PST, ID: 20833410

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 08:50AM PST, ID: 20833513

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Access Coding/Macros
Tags: Microsoft, Access, 2007
Sign Up Now!
Solution Provided By: LSMConsulting
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.06.2008 at 09:11AM PST, ID: 20833722

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628