Avatar billede yxos Nybegynder
15. december 2003 - 19:58 Der er 7 kommentarer og
1 løsning

Combox svar skal opdatere tabelfelt.

Hermed mit første spørgsmål i eksperten.dk:
Jeg har en 2 tabeller; Konto og KontoIbrug med felterne:
Konto:
Konto
Kontonavn
Saldo
KontoIbrug
Konto

Der er en 1:1 relation mellem felterne Konto, således at den ene record i Kontoibrug skal have en konto, der findes i tabel Konto.

Jeg vil gerne have en comboxbox (cmbKonto) i formular frmMain hvor jeg kan vælge hvilken konto fra tabellen konto, der skal stå i tabellen KontoIbrug.

Jeg er kommet så langt at jeg som rækkekilde (RowSource) har følgende;
SELECT [Konto].[Konto], [Konto].[KontoNavn] FROM [Konto]

Jeg har også lavet følgende, som virker, som placerer den valgte konto i variablen NyKontoIbrug:

Private Sub cmbKonto_AfterUpdate()
    NyKontoIbrug = (Me![cmbKonto]) 
End Sub

Hvordan får jeg NyKontoIbrug til at overskrive den eksisterende værdi i tabel Konto, felt konto ?
Avatar billede terry Ekspert
15. december 2003 - 20:17 #1
yxos>I think you need to alter your tables slightly!

KontoIbrug
----------
KontoID  (autonumber)
Konto    text

Then change Konto in the Konto table to a long integer. You can do this by using the lookup wizard in the Data type list. This will create a relationship between you tabels. If you now make a form using the form wizard you will automatically get a combo which takes the value from KontoIbrug and puts it in Konto!
Avatar billede terry Ekspert
16. december 2003 - 18:24 #2
Og?
Avatar billede yxos Nybegynder
16. december 2003 - 19:47 #3
Thanks for your suggestion Terry, but it didn't work out as you said.
There is already a one-to-one relation defined between those two tables. This is how it should be I believe.
Problem is that the combo is based on table Konto; not table KontoIbrug.
Therefore I can browse the accounts (konti) from table Konto, selecting any account I want but it will never be moved into KontoIbrug!Konto.
Would it be possible for you maybe to send a small sample to me that illustrates? Two tables; one form; one combo. (Access 2000)
yxos@hotmail.com
Avatar billede terry Ekspert
16. december 2003 - 20:03 #4
you can send me your database and I can do it for you NOSPAMeksperten@santhell.dkNOSPAM

remove NOSPAM from email address
Avatar billede yxos Nybegynder
16. december 2003 - 20:43 #5
I sent it.
Avatar billede terry Ekspert
17. december 2003 - 17:29 #6
I have returned your dB

Answer for others>

I don’t fully understand what it is you are trying to do so it isn’t easy to make suggestions to a possible solution.

Normally I would use an autonumber as the primary key, not a text field.
Why do you need a 1:1 relationship? You could have a yes/no field in table Konto which gets set to TRUE (yes) for the konto which is in use. The other two konto are obviously set to FALSE (no).

The reason why you are having problems with this is because the primary key in table kontoibrug (field = konto) can’t be changed! So I have added a new primary key (autonumber) and then changed the konto field which is actually the foreign key to a unique index so that it is not possible to create more than one with the same value.

This is a solution but I must admit I don’t see the point!

mvh
Terry
Avatar billede yxos Nybegynder
17. december 2003 - 21:37 #7
The point is to have one konto marked as "default konto".  Always!

You didn't say it here, but in you mail you suggested to skipping table KontoIbrug and instead intruce a ned yes/no field in table Konto; "Ibrug"

I did that and now it works!
My event looks like this:

Private Sub cmbKonto_AfterUpdate()
   
    DoCmd.OpenQuery "qsletkontoibrug"  'Set all Konto!Ibrug to "No"
   
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[Konto] = '" & Me![cmbKonto] & "'"
    Me.Bookmark = rs.Bookmark
    [Ibrug].Value = -1
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
   
End Sub

When using the Combo, I will always have one (and only one) record in table Konto marked with Yes in "Ibrug".
Avatar billede terry Ekspert
18. december 2003 - 09:43 #8
Yes I suggested a Yes/no field, but as I wabt sure what you were looking for I tried keeping to the same idea as you were using yourself. But what is important is that you found a solution which works for you :o)

and thanks!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester