modem Posted May 8, 2008 at 05:44 PM Report Share #184009 Posted May 8, 2008 at 05:44 PM Olá pessoal, preciso de fazer uma coisa estranha em Access: Tenho uma query que me dá uma tabela deste tipo: Cliente | Valor A | 2 A | 6 A | 15 B | 4 C | 6 C | 8 e pretendo fazer uma query que agarre neste resultado e me dê uma tabela tipo: Cliente | Valores A | 2;6;15 B | 4 C | 6;8 ou seja, que me transforme os diversos valores numa espécie de string... Como é que posso fazer isto? Já estive a ver as funções existentes mas não encontrei nenhuma que me desse algo como isto. Suponho que tenha de fazer uma função em VBA, mas não é o meu forte. Alguém pode ajudar? Link to comment Share on other sites More sharing options...
jpaulino Posted May 8, 2008 at 08:29 PM Report Share #184050 Posted May 8, 2008 at 08:29 PM Pessoalmente não conheco nenhum query que faça isso. Só em VBA. Está a usar que versão e queres colocar essa informação noutra tabela ou para visualizar (lista, relatório, etc) ? Link to comment Share on other sites More sharing options...
modem Posted May 9, 2008 at 09:12 AM Author Report Share #184113 Posted May 9, 2008 at 09:12 AM Olá, estou a usar a versão 2003 e pretendo obter o resultado em query ou tabela, que depois vai ser inserida numa folha excel de forma automática usando o import external data. A ideia seria criar uma função que fizesse isso e que pude-se ser incluida na query como as funções já existentes do Access. Mas como nunca fiz nenhuma coisa assim nem sei por onde começar, nem que tipo de argumentos passar. Link to comment Share on other sites More sharing options...
modem Posted May 9, 2008 at 01:08 PM Author Report Share #184152 Posted May 9, 2008 at 01:08 PM Já consegui! Estou maravilhado comigo mesmo 😄 Criei uma função muito simples: Dim ss As String Dim Last_Client As Integer Function ConvArray(Client As Integer, obj As String) As String If Last_Client = Client Then ss = ss & obj & ";" Last_Client = Client Else ss = obj & ";" Last_Client = Client End If ConvArray = ss End Function depois é só usar na query ConvArray(Cliente;valor) e definir o total para Max. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now