Visualizzazione dei risultati da 1 a 4 su 4

Discussione: vbNet Listbox e Access

  1. #1

    vbNet Listbox e Access

    salve a tutti e scusate ancora la rottura...

    io sto imparando per puro scopo personale VBNET,passando da vb6 a vbnet.

    io mi sono creato una libreria dei miei Dvd,e ho due listbox dove in una ho tutti i dvd,e cliccando su un dvd nella listbox,lo seleziono e finisce nella altra lisbox dove e' presente un tasto stampa che in un modello precompilato excel crea una lista.
    tutti i dvd sono presenti in un database access.


    In un modulo:

    Global gCnGestione As ADODB.Connection
    Global gRsdvdtotali As ADODB.Recordset
    Global gsSQL As String

    Nella Form Load:

    lst_dvdscelti.Clear
    Set gCnGestione = New ADODB.Connection
    gCnGestione.Open "FILE NAME=" & App.Path & "\Database.udl"
    call caricalista
    end sub

    Private Sub Caricalista()
    lst_tuttidvd.Clear
    Set gRsdvdtotali = New ADODB.Recordset
    gsSQL = "SELECT * FROM dvdtotali"
    gRsdvdtotali.Open gsSQL, gCnGestione
    Do While gRsdvdtotali.EOF = False
    lst_tuttidvd.AddItem gRsdvdtotali("dvdtotali")
    lst_tuttidvd.ItemData(lst_tuttidvd.NewIndex) = gRsdvdtotali("Coddvd")
    gRsdvdtotali.MoveNext
    Loop
    gRsdvdtotali.Close
    End Sub


    Private Sub selezionadvd()
    Set gRsdvdtotali = New ADODB.Recordset
    gsSQL = "SELECT * FROM dvdtotali WHERE Coddvd = " & lst_tuttidvd.ItemData(lst_tuttidvd.ListIndex) & ""
    gRsdvdtotali.Open gsSQL, gCnGestione
    Do While gRsdvdtotali.EOF = False

    lst_dvdscelti.AddItem gRsdvdtotali("dvdtotali")
    lst_dvdscelti.ItemData(lst_dvdscelti.NewIndex) = gRsdvdtotali("Coddvd")
    gRsdvdtotali.MoveNext

    Loop
    gRsdvdtotali.Close
    End Sub

    ok cosi vado bene poi inserisco tutto nel modello excel:

    Private Sub Stampadvd()

    Dim dvd As String
    Dim dvdn As String
    Dim stit As String
    Dim count As Integer
    Dim excellapp As New Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Dim risp As Integer
    DoEvents
    frmSplash_Stampaincorso.Visible = True
    FRM_gdvd.Enabled = False

    risp = MsgBox("Vuoi stampare il documento?", 1, "Stampa dvd")
    If risp = 1 Then


    Set gRsdvdtotali = New ADODB.Recordset
    gRsdvdtotali.Open gsSQL, gCnGestione

    For i = 0 To lst_dvdscelti.ListCount - 1
    excellapp.Workbooks.Open App.Path & "\Data\modello.xls"

    excellapp.Worksheets(1).Select
    dvd = lst_dvdscelti.List(i)

    gsSQL = "SELECT * FROM dvdtotali WHERE dvdtotali = " & lst_dvdscelti.List(i) & ""
    dvd = " & lst_dvdscelti.List(i) & "
    excellapp.Cells(4, 6) = lst_dvdscelti.List(i)
    stit = lst_dvdscelti.List(i)


    Set gRsdvdGenerale = New ADODB.Recordset
    gsSQL = "SELECT * FROM " & stit & ""
    gRsdvdGenerale.Open gsSQL, gCnGestione
    count = 12
    Do While gRsdvdGenerale.EOF = False

    stit = gRsdvdGenerale("dvd")
    excellapp.Cells(count, 4) = stit
    count = count + 1
    gRsdvdGenerale.MoveNext
    Loop
    gRsdvdGenerale.Close

    excellapp.Cells(12, 3) = dvdn
    excellapp.Worksheets(1).PrintOut

    excellapp.ActiveWorkbook.Close False
    excellapp.Workbooks.Close

    stit = ""
    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set excellapp = Nothing
    Next i
    gRsdvdtotali.Close
    Else
    Call Impostazioniiniziali

    End If

    If Err Then
    MsgBox ("Il file " & stit & " non è stato trovato.")

    End If
    DoEvents
    FRM_gdvd.Enabled = True
    frmSplash_Stampaincorso.Visible = False
    FRM_gdvd.SetFocus

    dvd = ""
    dvdn = ""
    stit = ""
    excellapp.Quit
    Set excellapp = Nothing

    Call Impostazioniiniziali

    End Sub


    per vbnet come potrei fare?

    scusate se non e' proprio perfetto il codice cmq l'importante e' imparare piano piano!

  2. #2
    Utente di HTML.it L'avatar di Stoicenko
    Registrato dal
    Feb 2004
    Messaggi
    2,254
    utilizza i tag code o php.. così il codice è illeggibile

  3. #3
    Codice PHP:
    In un modulo:

    Global 
    gCnGestione As ADODB.Connection
    Global gRsdvdtotali As ADODB.Recordset
    Global gsSQL As String

    Nella Form Load
    :

    lst_dvdscelti.Clear
    Set gCnGestione 
    = New ADODB.Connection
    gCnGestione
    .Open "FILE NAME=" App.Path "\Database.udl"
    call caricalista
    end sub

    Private Sub Caricalista()
    lst_tuttidvd.Clear
    Set gRsdvdtotali 
    = New ADODB.Recordset
    gsSQL 
    "SELECT * FROM dvdtotali"
    gRsdvdtotali.Open gsSQLgCnGestione
    Do While gRsdvdtotali.EOF False
    lst_tuttidvd
    .AddItem gRsdvdtotali("dvdtotali")
    lst_tuttidvd.ItemData(lst_tuttidvd.NewIndex) = gRsdvdtotali("Coddvd")
    gRsdvdtotali.MoveNext
    Loop
    gRsdvdtotali
    .Close
    End Sub


    Private Sub selezionadvd()
    Set gRsdvdtotali = New ADODB.Recordset
    gsSQL 
    "SELECT * FROM dvdtotali WHERE Coddvd = " lst_tuttidvd.ItemData(lst_tuttidvd.ListIndex) & ""
    gRsdvdtotali.Open gsSQLgCnGestione
    Do While gRsdvdtotali.EOF False

    lst_dvdscelti
    .AddItem gRsdvdtotali("dvdtotali")
    lst_dvdscelti.ItemData(lst_dvdscelti.NewIndex) = gRsdvdtotali("Coddvd")
    gRsdvdtotali.MoveNext

    Loop
    gRsdvdtotali
    .Close
    End Sub

    ok cosi vado bene poi inserisco tutto nel modello excel
    :

    Private 
    Sub Stampadvd()

    Dim dvd As String
    Dim dvdn 
    As String
    Dim stit 
    As String
    Dim count 
    As Integer
    Dim excellapp 
    As New Excel.Application
    Dim xlBook 
    As Excel.Workbook
    Dim xlSheet 
    As Excel.Worksheet
    Dim risp 
    As Integer
    DoEvents
    frmSplash_Stampaincorso
    .Visible True
    FRM_gdvd
    .Enabled False

    risp 
    MsgBox("Vuoi stampare il documento?"1"Stampa dvd")
    If 
    risp 1 Then


    Set gRsdvdtotali 
    = New ADODB.Recordset
    gRsdvdtotali
    .Open gsSQLgCnGestione

    For 0 To lst_dvdscelti.ListCount 1
    excellapp
    .Workbooks.Open App.Path "\Data\modello.xls"

    excellapp.Worksheets(1).Select
    dvd 
    lst_dvdscelti.List(i)

    gsSQL "SELECT * FROM dvdtotali WHERE dvdtotali = " lst_dvdscelti.List(i) & ""
    dvd " & lst_dvdscelti.List(i) & "
    excellapp.Cells(46) = lst_dvdscelti.List(i)
    stit lst_dvdscelti.List(i)


    Set gRsdvdGenerale = New ADODB.Recordset
    gsSQL 
    "SELECT * FROM " stit ""
    gRsdvdGenerale.Open gsSQLgCnGestione
    count 
    12
    Do While gRsdvdGenerale.EOF False

    stit 
    gRsdvdGenerale("dvd")
    excellapp.Cells(count4) = stit
    count 
    count 1
    gRsdvdGenerale
    .MoveNext
    Loop
    gRsdvdGenerale
    .Close

    excellapp
    .Cells(123) = dvdn
    excellapp
    .Worksheets(1).PrintOut

    excellapp
    .ActiveWorkbook.Close False
    excellapp
    .Workbooks.Close

    stit 
    ""
    Set xlSheet Nothing
    Set xlBook 
    Nothing
    Set excellapp 
    Nothing
    Next i
    gRsdvdtotali
    .Close
    Else
    Call Impostazioniiniziali

    End 
    If

    If 
    Err Then
    MsgBox 
    ("Il file " stit " non è stato trovato.")

    End If
    DoEvents
    FRM_gdvd
    .Enabled True
    frmSplash_Stampaincorso
    .Visible False
    FRM_gdvd
    .SetFocus

    dvd 
    ""
    dvdn ""
    stit ""
    excellapp.Quit
    Set excellapp 
    Nothing

    Call Impostazioniiniziali

    End Sub 

  4. #4

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.