Form Edit Problems

MaxMadneSS

New member
Local time
Today, 10:42
Joined
Jul 4, 2016
Messages
7
I have 2 input forms and they are connected with 1-1 relation (enforced referential integrity checked).
The point is to add data in main Form then click button to open next Form and add data there as well.
But once I add data to second Form, and they are obviously related to data in main Form, I can no longer edit them in main Form. I can edit other data that has no match in second Form which means the code is working.

This is how tables look like:
(close enough:D)

Code:
[B][U]tblPIO[/U][/B]                                 [B] [U] tblPosmrtnina[/U][/B]
#ID ------------ 1-1  ---------- #IDPosmrtnina
Name                                      2016
LastName                               2015
...                                             ...
...                                             ...
And the code that is adding data to table looks like this
Code:
[COLOR=SeaGreen]'cmdAdd has 2 options
'1. adding new entry
'2.editing existing data[/COLOR]

    If Me.cmbID.Tag & "" = "" Then
[COLOR=SeaGreen]'option 1[/COLOR]
    CurrentDb.Execute "INSERT INTO PIO(ID, Ime, Prezime, JMBG, Adresa, [Broj Adrese],[Fiksni telefon], [Mobilni telefon], [Mesna zajednica], [Opština],[Penzija]," & _
    " [e-mail], [Beleške], [Preminuo], [Strana penzija])" & _
    " VALUES (" & Me.cmbID & ",'" & Me.cmbIme & "','" & Me.cmbPrezime & "','" & Me.txtJMBG & "','" & Me.cmbAdresa & "','" & Me.txtBr & "','" & Me.txtFiksni & "','" & _
    Me.txtMobilni & "','" & Me.cmbMesnaZajednica & "','" & Me.cmbOpstina & "','" & Me.txtPenzija & "','" & Me.txtEmail & "','" & Me.txtBeleske & "','" & Me.chkPreminuo & "','" & Me.chkPenzija & "')"
    Else
[COLOR=SeaGreen]'option 2[/COLOR]
    CurrentDb.Execute "UPDATE PIO " & _
        " SET ID = '" & Me.cmbID & "', Ime = '" & Me.cmbIme & "', Prezime = '" & Me.cmbPrezime & "', Adresa = '" & Me.cmbAdresa & "'" & _
        ", [Broj Adrese] = '" & Me.txtBr & "', JMBG = '" & Me.txtJMBG & "', [Fiksni telefon] = '" & Me.txtFiksni & "'" & _
        ", [Mobilni telefon] = '" & Me.txtMobilni & "', [e-mail] = '" & Me.txtEmail & "', Opština = '" & Me.cmbOpstina & "'" & _
        ", [Mesna zajednica] = '" & Me.cmbMesnaZajednica & "', Penzija = '" & Me.txtPenzija & "', [Strana Penzija] = '" & Me.chkPenzija & "'" & _
        ", Preminuo = '" & Me.chkPreminuo & "', Beleške = '" & Me.txtBeleske & "'" & _
        " Where ID = " & Me.cmbID.Tag
    End If

    cmdClear_Click

    frmPIOSub.Form.Requery
Option 2 is obviously not working when there is relation or match in both Forms (or tables if you like).

I would really like to know how to fix this and what exactly is causing this problem.

Note: Altho I can remove primary keys and referential integrity which makes everything work like its supposed to, in which case I would just need more checks and coding in Form to avoid double entry's and similar things.

EDIT:
I missed to say that the code in Option 2 is working I debugged it and all the data is there everything is good but when you click Edit button nothing changes.
I get no error just like everything is ok, but all the data remain same as before editing.
 
Last edited:
Why do you have two tables?

Sent from my SM-G925F using Tapatalk
 
Second table has 40 checkboxes for all possible dates to check if someone paid smth on that specific year, so to say.

At the end I will need 2 more similar tables with another 40 checkboxes ... the point is I cannot display all that info in one table or Form.

EDIT:
Ok it seems I solved the problem after 7 days of nightmares

In option 2 above I made mistake with SQL statemant. Just needed to remove ID from UPDATE statemant to make it all work, since the ID is primary key which means it cannot be edited once connected trough relation with other ID's.
 
Last edited:
Your design is not efficient. That's ok if it works for now, but if you intend developing it further, then you will run into more and more problems.

Sent from my SM-G925F using Tapatalk
 
Ok, thanks.

EDIT: That solution makes sense indeed. Thanks again.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom