02. november 2004 - 20:36Der er
14 kommentarer og 2 løsninger
Automatisk nyt nummer afhængigt af produkttype
Jeg har en formular med en Combobox på. Comboboxen består af produkttyper. Hvis man vælger én produkttype, skal man når man trykker på CommandbtnOpretNyOrdre få et ordrenr som f.eks er 4500 + 1. Hvis man vælger en anden produkttype, skal man ved tryk på Cmdbtn få 4200 + 1 osv. Kan vha. en if sætning få Ordreformen til at skrive ex. 4500 i ordrenr feltet, men ikke lægge 1 til. Fejlmeddelelsen er ca.: Kan ikke tildele nr. da 1. formen er i design view (hvilket den ikke er) 2. nummeret er for stort? (har prøvet at bruge både autonr. og Integer) 3. noget med controls... Skal jeg bruge DMax og i så fald hvordan. Hvordan kan jeg bruge mine If If Else sætninger? Har brug for et detaljeret svar,please
I lang tid har samarbejdsbranchen fokuseret på at forbedre enhedsfunktioner – bedre kameraer, klarere lyd og smartere software. Men den virkelige forvandling handler ikke om funktioner.
Ja det ser ud som noget rigtigt, men jeg har brug for et mere detaljeret svar. Jeg er rimelig til Access, men ikke så stiv i VBA. Her er koden bag event proceduren on click bag cmdknappen. Skal ordrenr declareres i en variabel først og hvordan? Private Sub CmdButtonOpret_Click() On Error GoTo Err_CmdButtonOpret_Click Dim stDocName As String Dim stLinkCriteria As String
rbj_fp. I'm aware of the problem! "And you also need to make sure that the value returned doesnt go into the next inteval." and I should have also said: and that the the value doesnt already exist, which it can using your example too
If the user is picking a departmenttype or produkttype (Afd) which is f.ex. "40" the ordernr. will start at 1000. Forms!FrmOrdreMeddelOver![Projektnr].Value = [Projektnr] + 1000 This works fine, but I can't get it to add 1 to the ordernr. Furthermore I need to save the choice "40" in the table Orders, which is what the next line does (Forms!FrmOrdreMeddelOver![Afd].Value = "40")This I know is a clumsy solutions, but it works. My biggest problem is that I can't get it to add 1 to projektnr and save it in the table. Hope this makes sense
You can try this (NOT TESTED) although I am still not sure where ordrenr is used! If you cant get it to work then I think it would be best that I take a look at the dB.
Select Case me.combo13
'You need to alter the maximum values for each inteval so that it doesnt go into the next inteval when you add 1 Case 40 Ordrenr = Nz(DMax("OrdreNr", "tblOrdre", "OrdreNr >= 999 AND OrdreNr <= 4498"), 999) + 1
Case 42 Ordrenr = Nz(DMax("OrdreNr", "tblOrdre", "OrdreNr >= 4499 AND OrdreNr <= 9998"), 4499) + 1
Case Else MsgBox "Choose a valid departmenttype ..." Exit Sub
End Select
If DCount("OrdreNr", "tblOrdre", "OrdreNr = " & Ordrenr) > 0 Then MsgBox "OrdreNr exists ...." Else Forms!FrmOrdreMeddelOver![Projektnr].Value = Ordrenr Forms!FrmOrdreMeddelOver![Afd].Value = Me.combo13 End If
I've now given it a bit of a test and I think this is better
Select Case Me.combo13
'You need to alter the maximum values for each inteval so that it doesnt go into the next inteval when you add 1 Case 40 Ordrenr = Nz(DMax("OrdreNr", "tblOrdre", "OrdreNr >= 999 AND OrdreNr <= 4499"), 999)
Case 42 Ordrenr = Nz(DMax("OrdreNr", "tblOrdre", "OrdreNr >= 4499 AND OrdreNr <= 9999"), 4499)
Case Else MsgBox "Choose a valid departmenttype ..." Exit Sub
End Select
If DCount("OrdreNr", "tblOrdre", "OrdreNr = " & Ordrenr) > 0 Then MsgBox "OrdreNr exists ...." Else
Forms!FrmOrdreMeddelOver![Projektnr].Value = Ordrenr + 1 Forms!FrmOrdreMeddelOver![Afd].Value = Me.combo13 End If
To "Terry" Yes thank you very much. I've been doing some alterations today on the database. Amongst others I've moved the product type choice to the order form, and put some of your code in the on exit event procedure. Maybe that should have been in the on change procedure. I've only reached to try it on the choice of "40" - Ordrenr = Nz(DMax("OrdreNr", "tblOrdre", "OrdreNr >= 999 AND OrdreNr <= 4499"), 999), but it worked nicely. By the way isn't it right that the Case sentences are best when you're dealing with Integers or Number fields. That is what I seem to remember - my [Afd] field is now a text field in the TblType related to the TblOrder, but I suppose I should change it. I've tryed to give you and "Mugs" some points, but please comment if I've failed to do so.(I'm new at using this Experten site) Best regards and thank you for your quick replyes.
I think your right about using numbers in case sentences, although I'm sure you can use character values too. I myslef almost always try and use numbers.
Yes it went fine in sharing the points. (maybe too many to mugs :o) ) Have a nice evening, once again tak!
Synes godt om
Ny brugerNybegynder
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.