Results 1 to 2 of 2
  1. #1
    PetXC is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    1

    Why my combobox items are deleted

    Hi there. I've created the form "Formularz" but it does not work as i expected. In a form delete button "Usuń" should remove records from query "Kwerenda" only but it is removing items also from my combo boxes named "Miasto", "Ulica". Records in queries "Kwerenda1" and "Kwerenda2" are related with both combo boxes in form and should be read only (can not be deleted). My solutions works as it should if i will open a form, create a record and remove a record using this delete button without closing of a form window. The described problem is when i will open a form, create a record, close a form window, open a form next time and finally delete a saved record using a delete button. Any ideas how to solve that problem? Btw. Sorry for my english, i'm polish xD This is my VBA code:



    Option Explicit
    Option Compare Database


    Private Sub Form_BeforeUpdate(Cancel As Integer)
    On Error Resume Next
    If IsNull(Me.Ulica.Value) Then
    MsgBox "Brak ulicy"
    Cancel = True
    Me.Ulica.Value.SetFocus
    End If
    If IsNull(Me.Miasto.Value) Then
    MsgBox "Brak miasta"
    Cancel = True
    Me.Miasto.Value.SetFocus
    End If
    End Sub


    Private Sub cmdNew_Click()
    Me.AllowAdditions = True
    DoCmd.RunCommand acCmdRecordsGoToNew
    End Sub


    Private Sub cmdUsunRekord_Click()
    On Error GoTo Err_cmdUsunRekord_Click
    DoCmd.SetWarnings False
    If MsgBox("Confirm deletion of the record?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdDeleteRecord
    End If
    Exit_cmdUsunRekord_Click:
    DoCmd.SetWarnings True
    Exit Sub
    Err_cmdUsunRekord_Click:
    MsgBox Err.Description
    Resume Exit_cmdUsunRekord_Click
    End Sub


    Private Sub Form_Delete(Cancel As Integer)
    On Error Resume Next
    Miasto.Value.Cancel = True
    Ulica.Value.Cancel = True
    End Sub
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Suggest you give objects more meaningful names than Tabela, Tabela1, Tabela2. What is this database for? What is the data in the tables?

    Why reference the queries in combobox RowSource? Especially since the queries are not filtered and not sorted. Can just refer directly to the tables. Same for the form RecordSource. Just reference the tables in an SQL statement in the properties:

    SELECT Tabela.ID, Tabela.Miasto, Tabela.Ulica, IIf([Tabela1]![Punkty]+[Tabela2]![Punkty]<5,"Tak","Nie") AS Tekst, [Tabela1]![Punkty]+[Tabela2]![Punkty] AS Punkty
    FROM (Tabela INNER JOIN Tabela1 ON Tabela.Miasto = Tabela1.Miasto) INNER JOIN Tabela2 ON Tabela.Ulica = Tabela2.Ulica;

    SELECT Miasto FROM Tabela1 ORDER BY Miasto;

    SELECT Ulica FROM Tabela2 ORDER BY Ulica;


    I made these changes and deleted the 3 queries. I am not seeing records deleted from the lookup tables. I did not test deletion before I edited db.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Deleting Combobox/Dropdown Menu Items
    By tanyalee123 in forum Access
    Replies: 2
    Last Post: 02-27-2015, 11:42 AM
  2. Replies: 1
    Last Post: 12-04-2013, 09:21 AM
  3. Replies: 10
    Last Post: 07-23-2013, 05:07 PM
  4. delete query produce #deleted in all deleted values
    By learning_graccess in forum Queries
    Replies: 2
    Last Post: 03-31-2012, 07:20 AM
  5. Items With Which items Most Commonly
    By vansicklej in forum Access
    Replies: 3
    Last Post: 08-10-2011, 11:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums