Avatar billede woolbox Nybegynder
25. marts 2003 - 17:05 Der er 25 kommentarer og
1 løsning

3 spg: Relativ linktable DB-path/Foranstillet nuller /Lookup....

Det her i virkeligheden 3 spørgsmål, der er 30 points for hvert :)

Jeg er igang med et projekt, en journalhåndterings system i Access.

1: Hvordan henter jeg data fra en anden tabel via et relationship? Jeg har 3 tabeller som er relavante i denne sammenhæng: [Sager], [Abonnenter] og [Institutioner]. Sammenhængen er at hver abonnent har en eller flere institutioner unders sig. På hver institution er angivet om regning for netop denne institution, skal sendes til abonnenten eller institutionen.
På hver record i [Sager] er der angivet en Institution, og udfra dette relationship skal jeg på min Sags-form (eller en rapport, er vidst ligemeget?) hente adressen på enten Institutionen eller Abonennten som regningsadresse. Regningsadresse skal ikke registreres udover på abonnent/institution men være et lookup som foretages når formen/rapporten åbnes.

2: Systemet er delt op i 2 Access databaser, en ren frontend og en ren data - dette for at jeg kan opdatere GUI op sende ud til dem, uden at de skal til at eksportere nuværende data og importere dem i deres nye system.
Mit problem er at Access link til data-databasen er en absolut sti istedet for en relativ! :(
Jeg har IKKE systemet liggende på C-drevet på den maskine jeg udvikler på, hvilket betyder at når jeg kopierer den til deres maskine, så skal jeg genoprette tablelinks, meget ufedt! Er det ikke muligt at angive en relativ sti, eller på anden måde sørge for at dette ikke sker? Jeg havde forestillet at hvis man linker til en DB i samme mappe, at Access så selv finder ud af det, hvis begge filer flyttes til en anden mappe?!

3: Sagsnummer er bygget op af <år>.<fortløbende nummer> - fx. 03.0123. Dette repræsentere sag nummer 123 i år 2003. Hvordan sørger jeg for at dette fungere? Jeg har en knap til at oprette en ny sag, hvor der i forvejen bliver kørt noget kode. Hvordan sørger jeg smartest for at "sagsnummer" automatisk genereres ud for de kriterier jeg har nævnt? Måske noget med at have en "system-tabel" i ACcess, hvor jeg registrere hvilket sagsnummer basen er nået til eller? Og i givet fald, hvordan konverterer jeg et nummer fx. fra en tabel over system-variable til text og "sætter nuller foran"?
Avatar billede terry Ekspert
25. marts 2003 - 17:23 #1
1: Hvordan henter jeg data fra en anden tabel via et relationship?
You make a query adding the necessary tables. Then IF youhave designed your database correctly you will see thin lines JOINing the tables. So it should be just a case of selecting  the fields you want to see.
If there are NO thin lines JOINing the tables then drag and drop the primary key field on to the foreign key field in the related table. You can then right click the thin line to modify the JOIN type from an INNER to an OUTER (left or right).
Avatar billede terry Ekspert
25. marts 2003 - 17:30 #2
Well the easiest solution is to move the backend to (for example) your C: drive so that the path will be the same for all users. OR do this just before you send the dB out.
What I dont understand is IF the backend is on a server and the same backend is used for ALL users (also you when developing) then there shoul dbe no need to re-link.
Avatar billede terry Ekspert
25. marts 2003 - 17:38 #3
That was an asnwer to 2:
This is an answer to 3:
The only way you can dio this IS via code (IF you must have this format for Sagsnummer )
You have a system table which starts at 1 and you read this to get the next number. In the form where you need to create "Sagsnummer" you place this in the forms BEFORE UPDATE event

If me.isnewrecord Then
me.Sagsnummer = Format(Year(date()), "00") & Format(Dlookup("NextSaysNummer", "YourSysTable"), "0000")

Docmd.runsql "UPDATE YourSysTable SET NextSaysNummer = NextSaysNummer +1"

end if

NOTE: THis is NOT tested and you need to alter the table/field names accordingly
Avatar billede terry Ekspert
25. marts 2003 - 17:41 #4
that should be if me.newrecord
Avatar billede woolbox Nybegynder
28. marts 2003 - 23:27 #5
Thanx Terry, that was fast! :)

Sorry I haven't had time to look further into it yet, I will this weekend and let give you a response! :)
Avatar billede woolbox Nybegynder
01. april 2003 - 15:26 #6
1:
This part is upgraded to 60 points, think we need an illustration here! :) -

[http://www.rask.d2g.com/diverse/eksperten.dk/spm/333268/Exp333268a.png] shows the

relevant relationship in this case.

Each 'Sag' has a billing address, which is determined by the 'Institution' selected

(A). Each 'Institution' has two billing address options (B), either the

'Institution' itself or the 'Abonnent' tied to the 'Institution'. Depending on the

value of (B), the address information from either the 'Institution' (C) og the

'Abonnent' (D) should be used on the 'Sager' form's textfields with the billing

address (E).

Is this possible? - The solution must also be compatible with reports, so that it

can be used to print out a billing invoice.

Hope you understand what I'm trying to formulate!? :)

2:
"Well the easiest solution is to move the backend to (for example) your C: drive so

that the path will be the same for all users. OR do this just before you send the

dB out.
What I dont understand is IF the backend is on a server and the same backend is

used for ALL users (also you when developing) then there shoul dbe no need to

re-link."

- That's kind of what I'm doing now, but in my dev. environment, the DB resides on my server. But at my customer, the DB resides on one local machine. I would just like to avoid relinking DB when switchin from dev. to production environment, is it really not possible to link DB's using relative link?

3:
I'm cheking this out now! :)
Avatar billede terry Ekspert
01. april 2003 - 18:05 #7
1:Yes its possible :o)
You make a query and add the fields you want other than those to the billing address. Now you have to make one calculated field for each field in the billing address. You do this by entering "something" like this in an empty field in the query

N:iif([RegningTil]=1;[Institutioner]![Navn];[Abonnenter]![Navn])

Explanation:
N will be the name of the column (field) in the query, I think you can use Navn here without any problem.
iif() is a function like IF. IF [RegningTil]=1 then I use [Institutioner]![Navn] otherwise I use [Abonnenter]![Navn]

You need to do this for all fields in the address.

2: When you say relative sti I take it you mean ./SomedB.mdb
or something like that. No as far as I know you cant.
There are a number of ways around this problem but WILL require a bit of programming.

3:
Let me know how it goes :o)
Avatar billede terry Ekspert
01. april 2003 - 18:06 #8
in 1: You obviousply replace N with the name you want to give the column for example navn or Kontakt
Avatar billede woolbox Nybegynder
02. april 2003 - 01:07 #9
1: Looking at this now, just to get things straight: ControlSource equals "iif([Sager]![RegningTil]='institution';[Institutioner]![Navn];[Abonnenter]![Navn])" - should be ok?

2: Yes something like that, or in this case just "data.mdb" :) - When you say 'a bit of programming', are we then talking OS-size code, ora few lines? :)

3: Nothing happens, this is on my form, BeforeUpdate:

If Me.NewRecord Then
Me.TextSagsnr = Format(Year(Date), "00") & Format(DLookup("NextSagsnr", "System"), "0000")
DoCmd.RunSQL "UPDATE System SET NextSagsnr = NextSagsnr +1"
End If

But, if I create a button and assign the same piece of code it works fine! But, I'm not sure it's such a big problem, beacause I can just assign the code to the button I use for creating a new 'Sag' - I'll just try this :)
Avatar billede woolbox Nybegynder
02. april 2003 - 01:09 #10
3: Correction, it almost works with the button event, but the year is in 4 digits insted of 2, which seems odd when "00" is specified?
Avatar billede woolbox Nybegynder
02. april 2003 - 02:05 #11
1: With that line in ControlSource, i get "#Name?" - shouldn't I somehow specify from which record of Institution or Abonnent i should use Navn (or any other address information)?
Avatar billede terry Ekspert
02. april 2003 - 18:35 #12
1: This is in a query
2: Many lines. If you look around in Microsofts support I am sure I found an example.
3: Almost works?
Avatar billede woolbox Nybegynder
03. april 2003 - 03:17 #13
1: This works excellent!! - Thanx Terry, gonna start worship you soon! ;)
2: Think i found it, sound a bit like http://support.microsoft.com/default.aspx?scid=kb;en-us;210062 - but I'll stay completely out of it, haven't got a clue what they talk about, so this issue is also closed now! :)
3: Looking further into this now :)
Avatar billede woolbox Nybegynder
03. april 2003 - 03:26 #14
1: Hmm, geez a little thing more :) - One of the fields needed in the mailmerge, using the query is selected from another table. Problem is that the value stored in my DB is the ID in the other table, not the description field. Which means, that instead of getting a string i get the ID value from the other table. How do i get the corresponding text to that ID?
Avatar billede woolbox Nybegynder
03. april 2003 - 03:44 #15
3: It seem to work just fine, but there are a couple of things.

First of all, to comply with their current datastructure, the format must be YY.0000 - but i get YYYY.0000, kind'a weird!? :)

Second, what is the smartest way to handle a reset of the "nextSagsNr" when the year is changed? I was toying in my head with something like "current year" in my systable, and when i click new record, it checks if current year is different than actual year, and if so: reset the counter and set "actualyear" to the computers actual year - how does that sound? :)

Hope you can keep up with your patience, I'm kind of a newbee to this.

Lastly, how come you always write in english, it seems that you understand danish just fine - are you from US/UK/?
Avatar billede woolbox Nybegynder
03. april 2003 - 03:47 #16
Argh, me and my alzeimers! :( ...

3: Apart from the last issues, can I avoid the "You are about to update 1 row(s)" security warning, else i have to find another solution to increment the counter
Avatar billede terry Ekspert
03. april 2003 - 20:01 #17
1:In the query you add the other table. There may already be a thin line between the ID in both tables if not drag and drop the ID in one table onto the ID in the other table. You have now made an INNER JOIN. Now drag the description field into th equery :o)

2:This is more like what your looking for http://support.microsoft.com/default.aspx?scid=kb;en-us;275249

3: Yes I have tried that Format(Year(Date), "00")
Here is another idea Right(Year(date), 2)

3a: resetting nextSagsNr. You can have in your sys table the year which you are working with (2003). Then when you start the application or at some other time, you read the value and if it is differnt from Year(Date) you reset the nextSagsNr and dont forget to reset the year too :o)

3b: Docmd.setwarnings False
then make the updates
then docmd.setwarnings True

4: This must be worth extra points. I'm from the UK, only been in DK for 20 years so I'm not so good at writing danish yet :o)
Avatar billede woolbox Nybegynder
04. april 2003 - 03:56 #18
1: It works for one of the fields! :) - Though, I have two fields which lookup values in the same table, Receiver (of the case) and Assignee (of the case), when i add the field [Ansatte]![Navn], it fills in the last value i used, which would be Assignee. - This is the only thing missing now, my patient friend! :) :)

2: Not exactly less scary! ;) - I'll just relink the table on my C-drive before sending out the DB. Tnx anyway! :)

3: Right(... works like a champ!! :)
a: Works quite allright now! :) - One thing, how do i check if the sagsnr i just generated already exists? Naturally, sagsnr is indexed and cannot contain duplicates. If the computerclock screws up, or something else, and the same year is used for the second time, the counter would be reset, and i will generate a sagsnr that already exist. But instead of the odd error message, i'd like to be able to run some code (eg. simply displaying an alertbox). How to check if this sagsnr already exist?
b: Also perfect!!

4: Sure, I'll upgrade with one point! ;)
Avatar billede woolbox Nybegynder
10. april 2003 - 07:28 #19
Still there after the crash Terry?
Avatar billede terry Ekspert
10. april 2003 - 18:04 #20
1:I'm not quite sure I understand what you mean here!
2: :o)
3:
a: You can do this in a number of ways. IF your "sagsnr" is a unique key then IF it already exists and you will get an error. OR you can use 
If Dcount("*", "NameOfTable", "sagsnr = '" & TheNumberYouWantToCreate & "'") > 0 Then number already exists.
b: :o)

4: Tak :o)
Avatar billede woolbox Nybegynder
10. april 2003 - 18:23 #21
1: I have one table containing employees, i lookup values in this table from to different fields in Sager. One is for the receiver of the call, and one is the person the Sag is assigned to. So, if i just add "Navn" from "Ansatte" to my query, I only get the one whom the sag is assigned to.
While Exp.dk was down, I found out how to solve this! :) - I just add the table again (sort of a copy!?) to the query, and making the innerjoins between Ansatte to Receiver, and between Ansatte to AssignedTo :)

3A: Aaaah, great! :)

4: No prob

Thanx a lot terry, you deserved every little point! - Gonna replace my Vishnu with you! :D
Avatar billede terry Ekspert
11. april 2003 - 08:41 #22
Vishnu ?
and slev tak :o)
Avatar billede woolbox Nybegynder
11. april 2003 - 08:48 #23
Yeah, some hindu god with lots of arm ;)
Avatar billede terry Ekspert
11. april 2003 - 09:02 #24
well, sorry but I only have two :o)
Avatar billede woolbox Nybegynder
11. april 2003 - 09:14 #25
*LOL*
Avatar billede woolbox Nybegynder
20. august 2003 - 00:34 #26
Hi Terry, hope you're still online here?

If you're listening, have a look at http://www.eksperten.dk/spm/389768 - you helped me a great deal last time, and I think this is no prob. for a pro like you! :)
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