JOM
|
BOM JESUS DA LAPA BA - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 19/08/2007 20:25 hs
Vejam o codigo abaixo, tá dando o seguinte erro: tipo de dados incompativel com expressão de critério, mas ja verifiquei e só dá erro quando deixo o campo VALOR em branco, ele é do tipo currency, como remediar isto? Dim cnncomando As New ADODB.Command Dim rs_Pronaf As New ADODB.Recordset With cnncomando .ActiveConnection = cnnProjetos .CommandType = adCmdText .CommandText = " insert into projetos " & _ "(cod, data, cpf, nome, projetista, valor, atividade, municipio, porte)values ('" & _ Text_COD.Text & "','" & _ Text_DATA.Text & "','" & _ Text_CPF.Text & "', '" & _ Text_NOME.Text & "','" & _ Combo_PROJ.Text & "','" & _ Text_VALOR.Text & "','" & _ Combo_ATIV.Text & "','" & _ Combo_MUN.Text & "','" & _ Combo_PORTE.Text & "');" .Execute End With Set rs_Pronaf = Nothing Set cnncommando = Nothing Dim vOK As Integer vOK = MsgBox("Projeto salvo com sucesso", vbOKOnly + vbInformation, "Salvar Projeto") End Sub
|
|
|
|
|
Postada em 19/08/2007 22:55 hs
Uma possibilidade é tirar o campo: sSQL = "INSERT INTO projetos (cod, data, cpf, nome, projetista, " IF TRIM(Text_VALOR.Text) <> "" THEN sSQL = sSQL & "valor, " ENDIF sSQL = "atividade, municipio, porte)values ('" & _ Text_COD.Text & "','" & _ Text_DATA.Text & "','" & _ Text_CPF.Text & "', '" & _ Text_NOME.Text & "','" & _ Combo_PROJ.Text & "','" IF TRIM(Text_VALOR.Text) <> "" THEN sSQL = sSQL & Text_VALOR.Text & "','" ENDIF sSQL = sSQL & Combo_ATIV.Text & "','" & _ Combo_MUN.Text & "','" & _ Combo_PORTE.Text & "');"
.CommandText = sSQL e assim por diante. at+
|
|
|
|
Postada em 20/08/2007 15:06 hs
Bom companheiro se eu entendi bem seu problema, voce esta passando um valor com tipo de dado incompativel quando nulo ou seja "" valida o campo para receber "0" se nulo ou passa atravez da funcao VAL, que retornar zero se o campo estiver vazio (da no mesmo no frigir dos ovos) exemplo dim VdValor as double vdvalor = val(txtvalor.text) :D
|
|
|
|
Postada em 21/08/2007 10:25 hs
FAZ ASSIM Dim cnncomando As New ADODB.Command Dim rs_Pronaf As New ADODB.Recordset With cnncomando .ActiveConnection = cnnProjetos .CommandType = adCmdText .CommandText = " insert into projetos " & _ "(cod, data, cpf, nome, projetista, valor, atividade, municipio, porte)values ('" & _ Text_COD.Text & "','" & _ Text_DATA.Text & "','" & _ Text_CPF.Text & "', '" & _ Text_NOME.Text & "','" & _ Combo_PROJ.Text & "','" & IIF(Text_VALOR.Text="",0,Text_VALOR.Text) Combo_ATIV.Text & "','" & _ Combo_MUN.Text & "','" & _ Combo_PORTE.Text & "');" .Execute End With Set rs_Pronaf = Nothing Set cnncommando = Nothing Dim vOK As Integer vOK = MsgBox("Projeto salvo com sucesso", vbOKOnly + vbInformation, "Salvar Projeto") End Sub
|
|
|
JOM
|
BOM JESUS DA LAPA BA - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 21/08/2007 20:25 hs
valeu galera, meu trauma é que não possuo o access por isso fica dificil alterar as configurações do BD, pois faço eles usando o Visual Data Manager. achei interessante colocar um IF para só salvar com o campo preenchido, eu tava errando nisto também porque eu usava a expressão IF de forma errada, e logo após avisar sobre o campo obrigatório o código continuava a ser lido e parava no erro, mas colocando o IF no inicio e após o ELSE ele não continua a ler o código, evitando o erro, vou por o código pra vc's verem como ficou: Private Sub Cmd_SALVAR_Click() If Text_COD.Text = "" Then Dim vinfo As Integer vinfo = MsgBox("Não existe referência de Projeto para gravar dados no Gerenciador de Projetos, verifique.", vbOKOnly + vbCritical, "ATENÇÃO") Else If Text_VALOR.Text = "" Then Dim vcampo As Integer vcampo = MsgBox("O campo valor do Projeto não pode conter valor nulo.", vbOKOnly + vbInformation, "Campo obrigatório") Else Dim cnncomando As New ADODB.Command Dim rs_Pronaf As New ADODB.Recordset With cnncomando .ActiveConnection = cnnProjetos .CommandType = adCmdText .CommandText = " select * from projetos " Set rs_Pronaf = .Execute End With With rs_Pronaf rs_Pronaf.Filter = "cod = " & Text_COD.Text If .BOF And .EOF Then With cnncomando .ActiveConnection = cnnProjetos .CommandType = adCmdText .CommandText = " insert into projetos " & _ "(cod, data, cpf, nome, projetista, valor, atividade, municipio, porte)values ('" & _ Text_COD.Text & "','" & _ Text_DATA.Text & "','" & _ Text_CPF.Text & "', '" & _ Text_NOME.Text & "','" & _ Combo_PROJ.Text & "','" & _ Text_VALOR.Text & "','" & _ Combo_ATIV.Text & "','" & _ Combo_MUN.Text & "','" & _ Combo_PORTE.Text & "');" .Execute End With Dim vOK As Integer vOK = MsgBox("Projeto salvo com sucesso", vbOKOnly + vbInformation, "Salvar Projeto") Limpar_dados Else With cnncomando .ActiveConnection = cnnProjetos .CommandType = adCmdText .CommandText = " update projetos set " & _ "cod = '" & Text_COD.Text & "'," & _ "data = '" & Text_DATA.Text & "'," & _ "cpf = '" & Text_CPF.Text & "', " & _ " nome = '" & Text_NOME.Text & "'," & _ " projetista = '" & Combo_PROJ.Text & "'," & _ " valor = '" & Text_VALOR.Text & "'," & _ " atividade = '" & Combo_ATIV.Text & "'," & _ " municipio = '" & Combo_MUN.Text & "'," & _ " porte = '" & Combo_PORTE.Text & "'" & _ "where cod = " & Text_COD.Text & ";" .Execute End With vOK = MsgBox("Projeto salvo com sucesso", vbOKOnly + vbInformation, "Salvar Projeto")
Limpar_dados Set rs_Pronaf = Nothing Set cnncommando = Nothing End If End With End If End If End Sub
|
|
|
|