Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14

Discussione: problemi con isNull

  1. #1

    problemi con isNull

    ciao ragazzi, allora sto lavorando con le maschere access,
    Ora il mio problema è che nn riesco a costruire una if se il risultato della select è vuoto.
    vi posto il codice
    codice:
    strSQL = "SELECT * FROM gestione_merce WHERE  id  = " & id & " order by ID1 Desc"
    Set rstFieldData = New ADODB.Recordset
    With rstFieldData
      CursorType = adOpenKeyset
       .LockType = adLockOptimistic
       .Open Source:=strSQL, _
          ActiveConnection:=cnnConnect, _
            Options:=adCmdText
    End With
    Dim val1 As Integer
    Dim val2 As Integer
    Dim val3 As Integer
    If IsNull(rstFieldData(8)) = True Then
    val1 = Me.numero_confezioni.Value
    val2 = Me.unita_per_confezioni.Value
    If val1 <> 0 Then
    Me.totale_carico.Value = val1 * val2 + val3
    Else
    Me.totale_carico.Value = val2 + val3
    End If
    Else
    val3 = rstFieldData(8)
    If val1 <> 0 Then
    Me.totale_carico.Value = val1 * val2 + val3
    Else
    Me.totale_carico.Value = val2 + val3
    End If
    End If
    
    End Sub
    Praticamente quando aggiungo per la prima volta un record mi dice
    errore di run-time'3021'
    il record corrente corrisponde all'inizio o alla fine del file, per eseguire l'operazione è necessario disporre di un record corrente

  2. #2
    strSQL = "SELECT * FROM gestione_merce WHERE id = " & id & " order by ID1 Desc"


    :quote:
    quanto vale???

    strSQL = "SELECT * FROM gestione_merce WHERE id = " & id & " order by ID1 Desc"
    msgbox (strsql)

    Set rstFieldData = New ADODB.Recordset

    guarda se la stringa sql e giusta inserendo un msgbox
    -Raia Riccardo-
    Un forumello gnocco
    La vita è strana per questo bella

    non ero moderatore quando zork era un alcolizzato

  3. #3
    id = 9, la select funziona bene, perchè se ho altri record inseriti funziona

  4. #4
    praticamente se non ci sono altri record prende l'id del prodotto appena inserito.
    Come gli dico che se non esistono record precedenti non deve effettuare la select???

  5. #5
    strSQL = "SELECT * FROM gestione_merce WHERE id = " & id & " order by ID1 Desc"
    Set rstFieldData = New ADODB.Recordset
    With rstFieldData
    CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .Open Source:=strSQL, _
    ActiveConnection:=cnnConnect, _
    Options:=adCmdText
    End With
    Dim val1 As Integer
    Dim val2 As Integer
    Dim val3 As Integer
    If rstFieldData.EOF Then
    val1 = Me.numero_confezioni.Value
    val2 = Me.unita_per_confezioni.Value
    If val1 <> 0 Then
    Me.totale_carico.Value = val1 * val2 + val3
    Else
    Me.totale_carico.Value = val2 + val3
    End If
    Else
    val3 = rstFieldData(8)
    If val1 <> 0 Then
    Me.totale_carico.Value = val1 * val2 + val3
    Else
    Me.totale_carico.Value = val2 + val3
    End If
    End If

    End Sub

    prova così
    -Raia Riccardo-
    Un forumello gnocco
    La vita è strana per questo bella

    non ero moderatore quando zork era un alcolizzato

  6. #6
    mi da errore di sintassi alla riga
    [b]If rstFieldData.EOF Then [b]

  7. #7
    oppure anche così:

    function controllo()
    msgbox "Il prodotto non esiste"
    end function


    on error resume next
    strSQL = "SELECT * FROM gestione_merce WHERE id = " & id & " order by ID1 Desc"
    Set rstFieldData = New ADODB.Recordset
    With rstFieldData
    CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .Open Source:=strSQL, _
    ActiveConnection:=cnnConnect, _
    Options:=adCmdText
    End With
    if err.number = 3021 then
    call controllo()
    end if
    -Raia Riccardo-
    Un forumello gnocco
    La vita è strana per questo bella

    non ero moderatore quando zork era un alcolizzato

  8. #8
    errata corrige prima :gren:



    on error resume next
    strSQL = "SELECT * FROM gestione_merce WHERE id = " & id & " order by ID1 Desc"
    Set rstFieldData = New ADODB.Recordset
    With rstFieldData
    CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .Open Source:=strSQL, _
    ActiveConnection:=cnnConnect, _
    Options:=adCmdText
    End With
    if err.number = 3021 then
    control = "ok"
    end if
    Dim val1 As Integer
    Dim val2 As Integer
    Dim val3 As Integer
    If control = "ok" Then
    val1 = Me.numero_confezioni.Value
    val2 = Me.unita_per_confezioni.Value
    If val1 <> 0 Then
    Me.totale_carico.Value = val1 * val2 + val3
    Else
    Me.totale_carico.Value = val2 + val3
    End If
    Else
    val3 = rstFieldData(8)
    If val1 <> 0 Then
    Me.totale_carico.Value = val1 * val2 + val3
    Else
    Me.totale_carico.Value = val2 + val3
    End If
    End If

    End Sub

    cosi dovrebbe funzionare e dovrebbe essere anche lubrificato :gren:
    -Raia Riccardo-
    Un forumello gnocco
    La vita è strana per questo bella

    non ero moderatore quando zork era un alcolizzato

  9. #9
    così non mi serve, perchè è possibbilissimo caricare un prodotto che non è stato ancora caricato

  10. #10
    l'ultimo post inviato deve funzionare guarda bene...

    cmq così com'è il prodotto nn viene inserito nel database

    nn c'è nessun insert into o update

    :metallica
    -Raia Riccardo-
    Un forumello gnocco
    La vita è strana per questo bella

    non ero moderatore quando zork era un alcolizzato

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.