Hallo Ik het volgende stuk VBA wat werkt :
Echter als de naam die opgezocht is in een txt een ' bevat loopt de formule fout.
Is er iemand die me wil helpen om
dit stukje te herschrijven zodat ook namen met een ' er in meegenomen kunnen worden?
De VBA loopt hierop namelijk vast.
Ik gebruik deze code om een tabel te vullen die ik later weer uitlees. Ik moet de tabel selecteren op de naam die het meeste voorkomt. Echter als ik in de tabel instel sorteren A tot Z bij Aantal dan doet ie dat niet. Ik maak er eerst een query van daar blijft de sortering wel. Kan ik via insert into selecteren of kan dat gewoon niet?
Groet,
BB
Code:
Private Sub Selectie_Click()
DoCmd.RunSQL "DELETE * From SelectieAantalKoefamilie"
Dim DBase As DAO.Database
Nummer = -1
For teller = 1 To 100
MyKoeNaam = Array(Naam1, Naam2, Naam3, Naam4, Naam5, Naam6, Naam7, Naam8, Naam9, Naam10, Naam11, Naam12, Naam13, Naam14, Naam15, Naam16, Naam17, Naam18, Naam19, Naam20, Naam21, Naam22, Naam23, Naam24, Naam25, Naam26, Naam27, Naam28, Naam29, Naam30, Naam31, Naam32, Naam33, Naam34, Naam35, Naam36, Naam37, Naam38, Naam39, Naam40, Naam41, Naam42, Naam43, Naam44, Naam45, Naam46, Naam47, Naam48, Naam49, Naam50, Naam51, Naam52, Naam53, Naam54, Naam55, Naam56, Naam57, Naam58, Naam59, Naam60, Naam61, Naam62, Naam63, Naam64, Naam65, Naam66, Naam67, Naam68, Naam69, Naam70, Naam71, Naam72, Naam73, Naam74, Naam75, Naam76, Naam77, Naam78, Naam79, Naam80, Naam81, Naam82, Naam83, Naam84, Naam85, Naam86, Naam87, Naam88, Naam89, Naam90, Naam91, Naam92, Naam93, Naam94, Naam95, Naam96, Naam97, Naam98, Naam99, Naam100)
MyAantal = Array(TellerNaam1, TellerNaam2, TellerNaam3, TellerNaam4, TellerNaam5, TellerNaam6, TellerNaam7, TellerNaam8, TellerNaam9, TellerNaam10, TellerNaam11, TellerNaam12, TellerNaam13, TellerNaam14, TellerNaam15, TellerNaam16, TellerNaam17, TellerNaam18, TellerNaam19, TellerNaam20, TellerNaam21, TellerNaam22, TellerNaam23, TellerNaam24, TellerNaam25, TellerNaam26, TellerNaam27, TellerNaam28, TellerNaam29, TellerNaam30, TellerNaam31, TellerNaam32, TellerNaam33, TellerNaam34, TellerNaam35, TellerNaam36, TellerNaam37, TellerNaam38, TellerNaam39, TellerNaam40, TellerNaam41, TellerNaam42, TellerNaam43, TellerNaam45, TellerNaam45, TellerNaam46, TellerNaam47, TellerNaam48, TellerNaam49, TellerNaam50, TellerNaam51, TellerNaam52, TellerNaam53, TellerNaam54, TellerNaam55, TellerNaam56, TellerNaam57, TellerNaam58, TellerNaam59, TellerNaam60 _
, TellerNaam61, TellerNaam62, TellerNaam63, TellerNaam64, TellerNaam65, TellerNaam66, TellerNaam67, TellerNaam68, TellerNaam69, TellerNaam70 _
, TellerNaam71, TellerNaam72, TellerNaam73, TellerNaam74, TellerNaam75, TellerNaam76, TellerNaam77, TellerNaam78, TellerNaam79, TellerNaam80 _
, TellerNaam81, TellerNaam82, TellerNaam83, TellerNaam84, TellerNaam85, TellerNaam86, TellerNaam87, TellerNaam88, TellerNaam89, TellerNaam90 _
, TellerNaam91, TellerNaam92, TellerNaam93, TellerNaam94, TellerNaam95, TellerNaam96, TellerNaam97, TellerNaam98, TellerNaam99, TellerNaam100)
Nummer = Nummer + 1
Naam = MyKoeNaam(Nummer)
Aantal = MyAantal(Nummer)
Set DBase = CurrentDb
DBase.Execute " INSERT INTO SelectieAantalKoefamilie " _
& "(AantalDierenAanwFam,NaamKoeFam) VALUES " _
& "('" & Aantal & "', '" & Naam & "');"
DBase.Close
Next teller
MsgBox "Records geselecteerd!"
End Sub
Echter als de naam die opgezocht is in een txt een ' bevat loopt de formule fout.
Is er iemand die me wil helpen om
Code:
DBase.Execute " INSERT INTO SelectieAantalKoefamilie " _
& "(AantalDierenAanwFam,NaamKoeFam) VALUES " _
& "('" & Aantal & "', '" & Naam & "');"
dit stukje te herschrijven zodat ook namen met een ' er in meegenomen kunnen worden?
De VBA loopt hierop namelijk vast.
Ik gebruik deze code om een tabel te vullen die ik later weer uitlees. Ik moet de tabel selecteren op de naam die het meeste voorkomt. Echter als ik in de tabel instel sorteren A tot Z bij Aantal dan doet ie dat niet. Ik maak er eerst een query van daar blijft de sortering wel. Kan ik via insert into selecteren of kan dat gewoon niet?
Groet,
BB