Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    paccatore is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2015
    Posts
    13
    No problem, the code128 seems to work...
    now I'm trying to call this GetNext function from another one that update the value (UltimoSegnacollo) in the table (Postazione), here the code:

    Code:
    Option Compare Database
    
    Function aggiorna_IDcollo()
      
        Dim strQuery2, IDc As String
        Dim db As DAO.Database
        Set db = CurrentDb
           
        strQuery2 = "UPDATE Postazione SET UltimoSegnacollo = " & GetNext((UltimoSegnacollo))
        db.Execute strQuery2, dbFailOnError
    
    Set strQuery2 = Nothing
    Set db = Nothing
    
    End Function
    but It returns runtime error n°5 on this line:

    aryX(3) = IIf(aryX(3) = "Z", 0, Chr(Asc(aryX(3)) + 1))



    I've no idea where's the mistake... If I link this function to a button click it works properly eg. AlphaTextField=GetNext(AlphaTextField)

    Sorry for the duplicates...

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Why do you have double () in the function call? Where is aggiorna_IDcollo function? Where is it called from? It could be a Sub instead. Where is UltimoSegnacollo? Why are you using an UPDATE action? This UPDATE will change the UltimoSegnacollo value for every record in the table and I think all will be same value.

    How can this (AlphaTextField=GetNext(AlphaTextField)) work? You would be replacing an existing value with the new value. If AlphaTextField is a field in table then you are changing the data in record.
    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.

  3. #18
    paccatore is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2015
    Posts
    13
    I'm sorry for the lack... In the meaning I bypassed my issue calling that code by a refresh query and it works.
    But now I don't know why this part of my function doesn't works. In facts if I add the SET instruction on the line n° x I got "compilation error, object necessary", not whit pos9 = TBpstz.Fields("PosizioneNove")...
    Code:
    Option Compare Database
    Option Explicit
    
    Public Function moltiplicaRG()
    
    'imposta le variabili db (database), rst(tab sorgente), rst_new(tab destinazione), num (numeratore intero)
    Dim db As DAO.Database
    Set db = CurrentDb
    Dim TBpstz As DAO.Recordset
    Dim rst, rst_new As DAO.Recordset
    Dim num As Integer, IDc As String
    Dim codcli, pos9 As String
    
    Set rst = db.OpenRecordset("SELECT * FROM Selezione", , dbOpenSnapshot)
    Set rst_new = db.OpenRecordset("RigheGenerate", dbOpenDynaset)
    Set TBpstz = db.OpenRecordset("SELECT * FROM Postazione", dbOpenDynaset)
    Set codcli = TBpstz.Fields("CodiceIdentificativoCliente")
    Set pos9 = TBpstz.Fields("PosizioneNove")                                   ' < THIS IS THE X LINE WHERE DEBUG STOPS, THE NAME OF FIELD IS CORRECT! WHY VBA DOESN'T ACCEPTS "SET" THIS TIME?
    
    'verifica se il contatore dei colli si è esaurito
    If TBpstz("UltimoSegnacollo") = "Z999" Then
    MsgBox "Questa postazione SDA è satura." & vbCrLf & "Sovrascrivere i dati nella prossima finestra con quelli  della nuova postazione fornita da SDA."
        DoCmd.OpenTable "Postazione"
        
    Else
    
    'imposta le condizioni del loop
    While Not rst.EOF
    For num = 0 To rst.Colli - 1
    
    'imposta le azioni da intraprendere
    IDc = TBpstz.Fields("UltimoSegnacollo")
        
    'aggiorna UltimoSegnacollo su Postazione
    DoCmd.SetWarnings False
        DoCmd.OpenQuery ("013: Aggiorna UltimoSegnacollo su Postazione")
    DoCmd.SetWarnings True
    
        'accoda alla tabella righe generate
    rst_new.AddNew
    rst_new!NumeroDocumento = rst!NumeroDocumento
    rst_new!DataDocumento = rst!DataDocumento
    rst_new!Collo = num + 1
    rst_new!Colli = rst!Colli
    rst_new!Destinatario = rst!Destinatario
    rst_new!Indirizzo = rst!Indirizzo
    rst_new!CAP = rst!CAP
    rst_new!Localita = rst!Localita
    rst_new!Provincia = rst!Provincia
    rst_new!PesoLordo = rst!PesoLordo
    rst_new!LDV = rst!LDV
    rst_new!CodPorto = rst!CodPorto
    rst_new!Note = rst!Note
    rst_new!ImportoAssicurazione = rst!ImportoAssicurazione
    rst_new!CodServizio = rst!CodServizio
    rst_new!TipoServizio = rst!TipoServizio
    rst_new!IDcollo = Right(codcli, 4) & IDc & pos9 & rst!LDV
    rst_new.Update
    Next
    rst.MoveNext
    Wend
    
    'chiude gli oggetti e azzera le variabili
    TBpstz.Close
    rst.Close
    rst_new.Close
    db.Close
    
    End If
    End Function

  4. #19
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Set is to set an object, not populate a simple string variable.

    Just:

    pos9 = TBpstz.Fields("PosizioneNove")
    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.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Alphabet Labels on report
    By KyleL in forum Reports
    Replies: 2
    Last Post: 04-21-2014, 12:16 PM
  2. Alphabet linked to handsign
    By linda12 in forum Access
    Replies: 36
    Last Post: 09-22-2013, 11:28 AM
  3. Alphabet autoincrement
    By KWHAT in forum Access
    Replies: 16
    Last Post: 05-23-2012, 08:29 AM
  4. Cleaning up the alphabet
    By ducecoop in forum Access
    Replies: 4
    Last Post: 10-28-2010, 08:33 AM
  5. Alphabet break in report
    By amccook in forum Reports
    Replies: 8
    Last Post: 08-27-2010, 03:13 PM

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