HWV
Terugkerende gebruiker
- Lid geworden
- 19 feb 2009
- Berichten
- 1.213
Beste,
via de site van Paul Snip heb ik de code op via Word, excel gegevens op te vragen via een combobox.
http://www.paulsnip.nl/content/voorbeelden.asp?action=item&id=721&grp=0
Het werk allemaal goed, maar loop tegen het volgende aan.
Hij zoekt nu in de kolom Adresnaam1 om deze te plaatsen in de combobox, hier staat allemaal tekst in.
Nu wil ik de kolom Factuuradresnummer gaan gebruiken om te zoeken op adresnummer, maar dan geef hij een fout melding.
Type komt niet overeen.
Dit komt waarschijnlijk door dat er getallen in staan.
Hoe kan ik het toch werkend krijgen om te zoeken op debiteurennummer
Ik heb ook een aantal woorden die ik wil vervangen, maar volgens mij moet deze code veel korter kunnen maar kom er ook niet in uit.
Alvast bedankt HWV
via de site van Paul Snip heb ik de code op via Word, excel gegevens op te vragen via een combobox.
http://www.paulsnip.nl/content/voorbeelden.asp?action=item&id=721&grp=0
Het werk allemaal goed, maar loop tegen het volgende aan.
Hij zoekt nu in de kolom Adresnaam1 om deze te plaatsen in de combobox, hier staat allemaal tekst in.
Nu wil ik de kolom Factuuradresnummer gaan gebruiken om te zoeken op adresnummer, maar dan geef hij een fout melding.
Type komt niet overeen.
Dit komt waarschijnlijk door dat er getallen in staan.
Hoe kan ik het toch werkend krijgen om te zoeken op debiteurennummer
Ik heb ook een aantal woorden die ik wil vervangen, maar volgens mij moet deze code veel korter kunnen maar kom er ook niet in uit.
Alvast bedankt HWV
Code:
Private Sub UserForm_Initialize()
c4 = FindWindow("ThunderDFrame", Me.Caption)
SetWindowLong c4, -16, 0
DrawMenuBar c4
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
conn.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & ActiveDocument.Path & "\GST1-Export klanten.xls;"
rs.Open "SELECT * FROM [Sheet1$]", conn
Do While Not rs.EOF
ComboBox1.AddItem rs("Adresnaam1")
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
conn.Close: Set conn = Nothing
End Sub
Private Sub Invoegen_Click()
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
conn.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & ActiveDocument.Path & "\GST1-Export klanten.xls;"
rs.Open "SELECT * FROM [Sheet1$] WHERE Adresnaam1 = '" & ComboBox1 & "'", conn
Selection.GoTo wdGoToBookmark, , , "Adresnaam1"
Selection.Typeext rs("Adresnaam1")
Selection.GoTo wdGoToBookmark, , , "Adreslijn1"
Selection.TypeText rs("Adreslijn1")
Selection.GoTo wdGoToBookmark, , , "Localiteit"
Selection.TypeText rs("Postcode") & " " & rs("Localiteit")
Selection.GoTo wdGoToBookmark, , , "Factuuradresnummer"
Selection.TypeText rs("Factuuradresnummer")
Selection.GoTo wdGoToBookmark, , , "Vertegenwoordiger"
Selection.TypeText rs("Vertegenwoordiger")
Selection.GoTo wdGoToBookmark, , , "Telefoonnummer1"
Selection.TypeText rs("Telefoonnummer1")
'vervang code voor naam accountmanager
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "956"
.Replacement.Text = "Arno Verschoor"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "954"
.Replacement.Text = "Jan Willem van Duinen"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "955"
.Replacement.Text = "Gert van Duinen"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
'userform sluiten
Unload Me
End Sub