INSERT INTO X CAMPOS NULOS

USUARIO.EXCLUIDOS 21/08/2007 12:06:57
#231849
NO ERRO DE sintaxe VC ESTA COM CANPOS DE MAIS OU TEM ALGUNS NOMES DE CAMPOS Digitado errado de uma olhada bem no seu codigo
USUARIO.EXCLUIDOS 21/08/2007 12:16:44
#231852
Private Sub Cmd_SALVAR_Click()
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

tenta assim garoto.
USUARIO.EXCLUIDOS 21/08/2007 12:16:47
#231853
Resposta escolhida
Caro amigo, vc fez tres perguntas respondendo a Segunda: "vc deve sempre que abrir um recordset fecha-lo, isso evita a utilização da memoria para coisas que vc nem esta utilizando mais, porem se não fechar não ira dar erro. Terceira: vc pode sim passar um valor que não esta no formulário, para isso basta vc passa-lo entre aspas ex. ...','em analise','....

Quanto ao seu código, retire o espaço do inicio do insert e verifique se na sua tabela o campo "data" é do tipo data, se for ao inves de utilizar aspas utilize # #.

Falow

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

USUARIO.EXCLUIDOS 21/08/2007 20:27:28
#231935
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


USUARIO.EXCLUIDOS 21/08/2007 20:42:20
#231937
Opa! beleza, não tinha visto a segunda página, obrigado CEL_SUB7 pela explicação da segunda pergunta e também pela resposta da terceira que acabo de colocar e gravou beleza, logo após do ultimo campo do insert, pus o campo que faltava:

"(cod, data, cpf, nome, projetista, valor, atividade, municipio, porte, situacao)values

e no código pus, no final do insert into, como vc deu a dica:

Combo_PORTE.Text & "','EM ANÁLISE');"

ficou FILET!

Obrigado a todos e até a proxima, pois, com certeza virá...
Página 2 de 2 [15 registro(s)]
Tópico encerrado , respostas não são mais permitidas