Answered by:
Comparar texto com nome da tabela

Question
-
Boa noite!
É possível comparar um texto com o nome de uma campo em uma tabela ?
Ex.: Tenho uma tabela com campos (p300,p600,p1200,p1800 e etc), esse campos são do tipo Verdadeiro ou Falso, e na minha aplicação vai vim um parâmetro onde vai ser um texto (p300,p600,p1200,p1800 e etc) então precisava retorno somente os valores onde o campo for verdadeiro, mas primeiro precisava comparar qual campo vou verificar.
Digamos que meu parâmetro é p600, então teria que verificar a coluna p600, porem como tenho varias colunas gostaria de saber se tinha alguma forma de primeiro achar a colunar pra depois verificar se o valor daquela coluna é verdadeiro ou falso.
Pensei em usar ao mais ou menos assim, sendo que UtilizaVariavelGlobal('Plano') é a minha variavel que tem o mesmo nome do campo da tabela.
Select * from Tabela Where Tabela.UtilizaVariavelGlobal('Plano')=True
No lugar do p600 teria como colocar uma variável que vai ter o mesmo nome do campo ?
Obrigado !
https://onedrive.live.com/redir?resid=1CBDD42318B88DB7!8611&authkey=!ALSeuyl81SNWero&ithint=file%2czip
https://onedrive.live.com/redir?resid=1CBDD42318B88DB7!8611&authkey=!ALSeuyl81SNWero&ithint=file%2czip
- Edited by RJ_Silva Saturday, April 23, 2016 9:47 PM
Saturday, April 23, 2016 9:31 PM
Answers
-
Hi RJ_Silva,
This forum is English Forum, it would be helpful if you could post in English. According Google Translate, I got the questions below:
Good evening! You can compare a text with the name of a field in a table? Ex .: I have a table with fields (p300, p600, P1200, P1800, etc.), these fields are of type True or False, and my application will come a parameter which will be a text (p300, p600, P1200, P1800 etc.) then had to return only the values where the field is true, but first needed to compare what field I will check. Say my parameter is p600, would then have to verify the p600 column, however as I have several speakers wondered if he had somehow first find the columnar to then check if the value of that column is true or false. I thought of using the more or less well, and UtilizaVariavelGlobal ( 'Plan') is my variable that has the same name as the table field. Select * from Table Where Tabela.UtilizaVariavelGlobal ( 'Plan') = True In place of p600 would have put a variable that will have the same field name? Thank you ! https://onedrive.live.com/redir?resid=1CBDD42318B88DB7!8611&authkey=!ALSeuyl81SNWero&ithint=file%2czip https://onedrive.live.com/redir?resid=1CBDD42318B88DB7!8611&authkey=!ALSeuyl81SNWero&ithint=file%2czip
>>Select * from Table Where Tabela.UtilizaVariavelGlobal ( 'Plan') = True
What are you developing, and what is UtilizaVariavelGlobal? Your links are broken, I found nothing in them.
It Seems you want to check whether the field exist in Table, am I right? If so, I suggest you check the code below:
Function FieldExists(strFieldName As String, strTableName As String) As Boolean On Error GoTo DOESNOTEXIST Dim strTemp As String strTemp = CurrentDb.TableDefs(strTableName).Fields(strFieldName).Name FieldExists = True Exit Function DOESNOTEXIST: FieldExists = False EXIT_PROC: End Function
If I misunderstood you, please feel free to let me know.
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by RJ_Silva Thursday, April 28, 2016 8:09 PM
- Unmarked as answer by RJ_Silva Thursday, April 28, 2016 8:10 PM
- Proposed as answer by Edward8520Microsoft contingent staff Friday, April 29, 2016 2:21 AM
- Marked as answer by Edward8520Microsoft contingent staff Tuesday, May 3, 2016 2:27 AM
- Unmarked as answer by RJ_Silva Saturday, May 14, 2016 9:31 PM
- Marked as answer by RJ_Silva Saturday, May 14, 2016 9:31 PM
Monday, April 25, 2016 5:58 AM
All replies
-
One solution is to make an array with the table names and then loop through them in VBA:
Option Explicit Const TABLENAMES = "P300,P600,P1200,P1800" Sub test() Dim theNames As Variant Dim Count As Integer Dim Column As Integer Dim i As Integer theNames = Split(TABLENAMES, ",") Count = UBound(theNames) For i = 0 To Count For column = 1 to <rowcount for theNames(i)> ' ... examine if several speakers ... Next Column '... etc ... Next i End Sub
Best regards, George
Sunday, April 24, 2016 11:57 AM -
One solution is to make an array with the table names and then loop through them in VBA:
Option Explicit Const TABLENAMES = "P300,P600,P1200,P1800" Sub test() Dim theNames As Variant Dim Count As Integer Dim Column As Integer Dim i As Integer theNames = Split(TABLENAMES, ",") Count = UBound(theNames) For i = 0 To Count For column = 1 to <rowcount for theNames(i)> ' ... examine if several speakers ... Next Column '... etc ... Next i End Sub
Best regards, George
I'm not sure how to use the code in my query, it is possible to create a function to check the column name?
Sunday, April 24, 2016 5:02 PM -
Hi RJ_Silva,
This forum is English Forum, it would be helpful if you could post in English. According Google Translate, I got the questions below:
Good evening! You can compare a text with the name of a field in a table? Ex .: I have a table with fields (p300, p600, P1200, P1800, etc.), these fields are of type True or False, and my application will come a parameter which will be a text (p300, p600, P1200, P1800 etc.) then had to return only the values where the field is true, but first needed to compare what field I will check. Say my parameter is p600, would then have to verify the p600 column, however as I have several speakers wondered if he had somehow first find the columnar to then check if the value of that column is true or false. I thought of using the more or less well, and UtilizaVariavelGlobal ( 'Plan') is my variable that has the same name as the table field. Select * from Table Where Tabela.UtilizaVariavelGlobal ( 'Plan') = True In place of p600 would have put a variable that will have the same field name? Thank you ! https://onedrive.live.com/redir?resid=1CBDD42318B88DB7!8611&authkey=!ALSeuyl81SNWero&ithint=file%2czip https://onedrive.live.com/redir?resid=1CBDD42318B88DB7!8611&authkey=!ALSeuyl81SNWero&ithint=file%2czip
>>Select * from Table Where Tabela.UtilizaVariavelGlobal ( 'Plan') = True
What are you developing, and what is UtilizaVariavelGlobal? Your links are broken, I found nothing in them.
It Seems you want to check whether the field exist in Table, am I right? If so, I suggest you check the code below:
Function FieldExists(strFieldName As String, strTableName As String) As Boolean On Error GoTo DOESNOTEXIST Dim strTemp As String strTemp = CurrentDb.TableDefs(strTableName).Fields(strFieldName).Name FieldExists = True Exit Function DOESNOTEXIST: FieldExists = False EXIT_PROC: End Function
If I misunderstood you, please feel free to let me know.
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by RJ_Silva Thursday, April 28, 2016 8:09 PM
- Unmarked as answer by RJ_Silva Thursday, April 28, 2016 8:10 PM
- Proposed as answer by Edward8520Microsoft contingent staff Friday, April 29, 2016 2:21 AM
- Marked as answer by Edward8520Microsoft contingent staff Tuesday, May 3, 2016 2:27 AM
- Unmarked as answer by RJ_Silva Saturday, May 14, 2016 9:31 PM
- Marked as answer by RJ_Silva Saturday, May 14, 2016 9:31 PM
Monday, April 25, 2016 5:58 AM -
Hi RJ_Silva,
Have your issue been resolved? If you have, I suggest you mark helpful reply as answer, if not, please feel free to let us know your current situation.
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Friday, April 29, 2016 2:22 AM