IF NO UPDATE
EU TENHO NUMEROS E TEXTOS PARA FAZER UPDATE.
SO QUE QUANDO DEIXO ELES SEM PREENCHER; DA ERRO.
QUERO QUE OS VALORES SEJAM 0 OU NULO
SO QUE QUANDO DEIXO ELES SEM PREENCHER; DA ERRO.
QUERO QUE OS VALORES SEJAM 0 OU NULO
aqui esta minha string pra ver se podem me ajudar:
Conect.Execute ("update tabx set x1 = " & Text1 & ", x2=" & Text2 & ", x3=" & Text3 & ", x4=" & Text4 & ", x5=" & Text5 & ", x6=" & Text6 & ", x7=" & Text7 & ", x8=" & Text8 & ", x9=" & Text9 & ", x10=" & Text10 & ", x11=" & Text11 & ", y1=" & Text12 & ", y2=" & Text13 & ", y3=" & Text14 & ", y4=" & Text15 & ", y5=" & Text16 & ", y6=" & Text17 & ", y7=" & Text18 & ", y8=" & Text19 & ", y9=" & Text20 & ", y10=" & Text21 & ", y11=" & Text22 & ", c1='" & Text23 & "', c2='" & Text24 & "', c3='" & Text25 & "', c4='" & Text26 & "', c5='" & Text27 & "', c6='" & Text28 & "', c7='" & Text29 & "', c8='" & Text30 & "', c9='" & Text31 & "', c10='" & Text32 & "', c11='" & IIf(IsNull(Text33), "", Text33) & "'")
TENTEI NO ULTIMO FAZER ISSO, MAS DA ERRO
Conect.Execute ("update tabx set x1 = " & Text1 & ", x2=" & Text2 & ", x3=" & Text3 & ", x4=" & Text4 & ", x5=" & Text5 & ", x6=" & Text6 & ", x7=" & Text7 & ", x8=" & Text8 & ", x9=" & Text9 & ", x10=" & Text10 & ", x11=" & Text11 & ", y1=" & Text12 & ", y2=" & Text13 & ", y3=" & Text14 & ", y4=" & Text15 & ", y5=" & Text16 & ", y6=" & Text17 & ", y7=" & Text18 & ", y8=" & Text19 & ", y9=" & Text20 & ", y10=" & Text21 & ", y11=" & Text22 & ", c1='" & Text23 & "', c2='" & Text24 & "', c3='" & Text25 & "', c4='" & Text26 & "', c5='" & Text27 & "', c6='" & Text28 & "', c7='" & Text29 & "', c8='" & Text30 & "', c9='" & Text31 & "', c10='" & Text32 & "', c11='" & IIf(IsNull(Text33), "", Text33) & "'")
TENTEI NO ULTIMO FAZER ISSO, MAS DA ERRO
Qual erro dá?
Tente fazer uma função que retorne o valor ou "Null"
No caso de número
Conect.Execute ("update tabx set x1 = " & valsql(Text1.text) & ", x2=" & valsql(Text2.text) & (...)
Supondo que o campo text1 não tenha nada e text2 seja igual a 30, o comportamento seria esse:
Tente fazer uma função que retorne o valor ou "Null"
No caso de número
Function ValSQL(Texto as String) As String
If texto = "" then valsql = "Null" Else valsql = texto
End FunctionConect.Execute ("update tabx set x1 = " & valsql(Text1.text) & ", x2=" & valsql(Text2.text) & (...)
Supondo que o campo text1 não tenha nada e text2 seja igual a 30, o comportamento seria esse:
Update tabx set x1 = Null, x2 = 30 (...)
nao entendi o TEXTO no final da function
Texto é a variável que vai receber o valor do Text1.Text quando você passar o argumento da função.
Então:
Se Text1.Text = "" Então ValSQL = "Null" Senão ValSQL recebe o texto Texto.
Então:
Se Text1.Text = "" Então ValSQL = "Null" Senão ValSQL recebe o texto Texto.
Tente fazer o IIF em TODOS OS TEXTBOX
Nao deu certo assim
é, o Luiz tá certo, a essência da coisa é essa, a função que eu criei é só pra simplificar um pouco.
Coloque em todos e veja se dá erro (poste o erro pra gente ver).
A primeira providência que tomo nessas horas é dar um Debug.Print na SQL, pois todas essas variáveis, aspas e vÃrgulas costumam dar até tonteira na gente, mas no debug você vê o resultado final da sua sql e já com os valores, aà fica mais fácil identificar onde está o erro.
Outra dica é você tentar executar parcialmente porque se um campo der problema sua SQL inteira está errada...
Coloque em todos e veja se dá erro (poste o erro pra gente ver).
A primeira providência que tomo nessas horas é dar um Debug.Print na SQL, pois todas essas variáveis, aspas e vÃrgulas costumam dar até tonteira na gente, mas no debug você vê o resultado final da sua sql e já com os valores, aà fica mais fácil identificar onde está o erro.
Outra dica é você tentar executar parcialmente porque se um campo der problema sua SQL inteira está errada...
Nao cabe na mesma linha se colocar os iif, como faco?
coloquei so onde iria pegar o texto e deu esse erro:
Run-time error '3078':
The Microsoft Jet database engine cannot find the input table or query 'tabx'. Make sure it exists and that its name is spelled correcly.
Run-time error '3078':
The Microsoft Jet database engine cannot find the input table or query 'tabx'. Make sure it exists and that its name is spelled correcly.
Esse erro acima era do banco.. arrumei...
da esse erro agora:
Run-time error '3144':
Syntax error in UPDATE statement
(como faco o debug?)
da esse erro agora:
Run-time error '3144':
Syntax error in UPDATE statement
(como faco o debug?)
Tópico encerrado , respostas não são mais permitidas