Print side | Luk vindue

Genkald data

Udskrevet fra: Dansk Regneark Forum
Kategori: Hjælp til regneark.
Forum navn: Makro og VBA
Forum beskrivelse: Hjælp til Makroer og VBA-programmering
Web-adresse: https://forum.excel-regneark.dk/forum_posts.asp?TID=3148
Udskrevet den: 05.Dec.2026 kl. 16:43


Emne: Genkald data
Besked fra: Matlock
Emne: Genkald data
Posteringsdato: 04.Sep.2017 kl. 17:35
Hej Alle

Jeg har en Userform hvor i jeg vil lave en aftaleseddel.



Men kunne godt tænke mig at hvis jeg nu havde lavet en aftaleseddel, og overført værdierne til en database, at jeg kunne genkalde alle værdierne i userformen hvis jeg valgt et aftaleseddel nr. der allerede var blevet brugt igen.

Her er koden

Private Sub cmdAnnullere_Click()

    Unload Me
    
End Sub

Private Sub CommandButton1_Click()

    If cboAftale.Text = "" Then
        MsgBox "Skriv venligst aftaleseddel nr."
        txtaftaleseddelnr.SetFocus
        Exit Sub
    End If
    
    If txtDato.Text = "" Then
        MsgBox "Skriv venligst dato"
        txtDato.SetFocus
        Exit Sub
    End If
      
    If txtbesk.Text = "" Then
        MsgBox "Skriv venligst en beskrivelse af det udførte arbejde"
        txtbesk.SetFocus
        Exit Sub
    End If
    
    If txtVare1.Text = "" Then
        MsgBox "Skriv venligst en vare"
        txtVare1.SetFocus
        Exit Sub
    End If
    
    If txtPris1.Text = "" Then
        MsgBox "Skriv venligst en pris"
        txtPris1.SetFocus
        Exit Sub
    End If
    
    Worksheets("Aftaleseddel").Activate
    Range("K3").Select
    If Range("K3").Value = "" Then
        Range("K3").Activate
    End If
    With ActiveCell
        .Value = cboAftale.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("C47").Select
    If Range("C47").Value = "" Then
        Range("C47").Activate
    End If
    With ActiveCell
        .Value = txtDato.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("B15").Select
    If Range("B15").Value = "" Then
        Range("B15").Activate
    End If
    With ActiveCell
        .Value = txtbesk.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("B24").Select
    If Range("B24").Value = "" Then
        Range("B24").Activate
    End If
    With ActiveCell
        .Value = txtVare1.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("J24").Select
    If Range("J24").Value = "" Then
        Range("J24").Activate
    End If
    With ActiveCell
        .Value = txtPris1.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("B26").Select
    If Range("B26").Value = "" Then
        Range("B26").Activate
    End If
    With ActiveCell
        .Value = txtVare2.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("J26").Select
    If Range("J26").Value = "" Then
        Range("J26").Activate
    End If
    With ActiveCell
        .Value = txtPris2.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("B28").Select
    If Range("B28").Value = "" Then
        Range("B28").Activate
    End If
    With ActiveCell
        .Value = txtVare3.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("J28").Select
    If Range("J28").Value = "" Then
        Range("J28").Activate
    End If
    With ActiveCell
        .Value = txtPris3.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("B30").Select
    If Range("B30").Value = "" Then
        Range("B30").Activate
    End If
    With ActiveCell
        .Value = txtVare4.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("J30").Select
    If Range("J30").Value = "" Then
        Range("J30").Activate
    End If
    With ActiveCell
        .Value = txtPris4.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("B32").Select
    If Range("B32").Value = "" Then
        Range("B32").Activate
    End If
    With ActiveCell
        .Value = txtVare5.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("J32").Select
    If Range("J32").Value = "" Then
        Range("J32").Activate
    End If
    With ActiveCell
        .Value = txtPris5.Text
    End With
    
    
    Worksheets("Aftaleseddel").Activate
    Range("B34").Select
    If Range("B34").Value = "" Then
        Range("B34").Activate
    End If
    With ActiveCell
        .Value = txtVare6.Text
    End With
    
    Worksheets("Aftaleseddel").Activate
    Range("J34").Select
    If Range("J34").Value = "" Then
        Range("J34").Activate
    End If
    With ActiveCell
        .Value = txtPris6.Text
    End With
            
    nr = [Aftaleseddel!D2]
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\bbj\Desktop\Test\Aftalesedler\Aftaleseddel Nr" & nr & ".pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
        True
    
    Worksheets("Bilag B").Activate
    Range("E4").Select
    If Range("E4").Value = "" Then
        Range("E4").Activate
        Else
        Range("E4").CurrentRegion.Select
        ActiveCell.Offset(Selection.Rows.Count, 1).Activate
    End If
    With ActiveCell
        .Value = txtbesk.Text
        .Offset(0, 1).Value = Range("Aftaleseddel!Ialt")
        .Offset(0, 5).Value = txtDato.Text
        .Offset(0, 6).Value = txtVare1.Text
        .Offset(0, 7).Value = txtPris1.Text
        .Offset(0, 8).Value = txtVare2.Text
        .Offset(0, 9).Value = txtPris2.Text
        .Offset(0, 10).Value = txtVare3.Text
        .Offset(0, 11).Value = txtPris3.Text
        .Offset(0, 12).Value = txtVare4.Text
        .Offset(0, 13).Value = txtPris4.Text
        .Offset(0, 14).Value = txtVare5.Text
        .Offset(0, 15).Value = txtPris5.Text
        .Offset(0, 16).Value = txtVare6.Text
        .Offset(0, 17).Value = txtPris6.Text
        
    End With
        
    ActiveCell.Offset(1).EntireRow.Insert
    
    Worksheets("Aftaleseddel").Activate
        
    Range("K3").Select
    Selection.ClearContents
    
    Range("C47").Select
    Selection.ClearContents
    
    Range("B15").Select
    Selection.ClearContents
    
    Range("B24").Select
    Selection.ClearContents
    
    Range("J24").Select
    Selection.ClearContents
    
    Range("B26").Select
    Selection.ClearContents
    
    Range("J26").Select
    Selection.ClearContents
          
    Range("B28").Select
    Selection.ClearContents
    
    Range("J28").Select
    Selection.ClearContents
          
    Range("B30").Select
    Selection.ClearContents
    
    Range("J30").Select
    Selection.ClearContents
          
    Range("B32").Select
    Selection.ClearContents
          
    Range("J32").Select
    Selection.ClearContents
          
    Range("B34").Select
    Selection.ClearContents
    
    Range("J34").Select
    Selection.ClearContents
         
          
    Unload Me
    
End Sub
   
Private Sub UserForm_Activate()


    With cboAftale
        .RowSource = "Aftalenr"
        .ListIndex = 0
    End With

txtDato.Text = Format(Now, "dd-mmm-yyyy")


End Sub


Håber i kan hjælpe




Print side | Luk vindue