Ir para conteúdo
Fórum Script Brasil
  • 0

Rotina de Salvar não salva e da erro


Flecha

Pergunta

Quem pode ajudar!!

Tenho um form onde mostra uma listview com os registros e campos que escolhi e abaixo os textboxes dos dados completos do registro que esta destacado no listview.

Quando escolho um registro do listview e clico em alterar a função habilita os textboxes, faço a ateração e clico em gravar e pronto. Retorna o comando para a listview e o registro ficou alterado e salvo no BD.

Acontece que se eu escolher Incluir ele habilita os textboxes para inclusão, aceita os dados e quando clico em gravar dá o seguinte erro:

TIPO DE DADOS INCOMPATÍVEL NA EXPRESSÃO DE CRITÉRIO

Não sei como consertar.

Caso eu inclua um ON ERROR RESUME NEXT o registro até vai para o listview e eu achava que estava no BD mas não salva.

Segue ocodigo do botão salvar/editar

[Private Sub cmdSave_Click()

'-----------------------------------------------------------------------------

'On Error Resume Next

Dim strPhone As String

Dim strPhoneCel As String

Dim objNewListItem As ListItem

Dim lngIDField As Long

Dim strSQL As String

If Not ValidateFormFields Then Exit Sub

strPhone = txtArea.Text & txtPrfx.Text & txtLine.Text

strPhoneCel = TxtAreaC.Text & TxtPrfxC.Text & TxtLineC.Text

If mstrMaintMode = "ADD" Then

lngIDField = GetNextCustID()

strSQL = "INSERT INTO Customer( CustID"

strSQL = strSQL & " , NOME"

strSQL = strSQL & " , RG"

strSQL = strSQL & " , ENDEREÇO"

strSQL = strSQL & " , cidade"

strSQL = strSQL & " , CPF"

strSQL = strSQL & " , Bairro"

strSQL = strSQL & " , Nacionalidade"

strSQL = strSQL & " , Naturalidade"

strSQL = strSQL & " , Dtnato"

strSQL = strSQL & " , Pai"

strSQL = strSQL & " , Mae"

strSQL = strSQL & " , Posiçao"

strSQL = strSQL & " , Numero"

strSQL = strSQL & " , Complemento"

strSQL = strSQL & " , Civil"

strSQL = strSQL & " , estado"

strSQL = strSQL & " , cep"

strSQL = strSQL & " , TELRES"

strSQL = strSQL & " , TELCEL"

strSQL = strSQL & " , Obsa"

strSQL = strSQL & " , Cargo"

strSQL = strSQL & " , Classe"

strSQL = strSQL & " , Exercicio"

strSQL = strSQL & " ) VALUES ("

strSQL = strSQL & lngIDField

strSQL = strSQL & ", '" & Replace$(txtNOME.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(txtRg.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(txtENDEREÇO.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(txtCidade.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtCpf.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtBairr.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtNac.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtNat.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtNasc.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtPai.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtMae.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtPos.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtNum.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtCompl.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtCivil.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(TxtObs.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(Combo2.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(Combo3.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & Replace$(Combo1.Text, "'", "''") & "'"

strSQL = strSQL & ", '" & txtEstado.Text & "'"

strSQL = strSQL & ", '" & txtCep.Text & "'"

strSQL = strSQL & ", '" & strPhone & "'"

strSQL = strSQL & ", '" & strPhoneCel & "'"

strSQL = strSQL & ")"

Set objNewListItem = lvwCustomer.ListItems.Add(, , txtNOME.Text, , "Custs")

PopulateListItem objNewListItem

With objNewListItem

.SubItems(mlngCUST_ID_IDX) = CStr(lngIDField)

.EnsureVisible

End With

Set lvwCustomer.SelectedItem = objNewListItem

Set objNewListItem = Nothing

Else

lngIDField = CLng(lvwCustomer.SelectedItem.SubItems(mlngCUST_ID_IDX))

strSQL = "UPDATE Customer SET "

strSQL = strSQL & " NOME = '" & Replace$(txtNOME.Text, "'", "''") & "'"

strSQL = strSQL & ", RG = '" & Replace$(txtRg.Text, "'", "''") & "'"

strSQL = strSQL & ", ENDEREÇO = '" & Replace$(txtENDEREÇO.Text, "'", "''") & "'"

strSQL = strSQL & ", cidade = '" & Replace$(txtCidade.Text, "'", "''") & "'"

strSQL = strSQL & ", CPF = '" & Replace$(TxtCpf.Text, "'", "''") & "'"

strSQL = strSQL & ", Bairro = '" & Replace$(TxtBairr.Text, "'", "''") & "'"

strSQL = strSQL & ", Nacionalidade = '" & Replace$(TxtNac.Text, "'", "''") & "'"

strSQL = strSQL & ", Naturalidade = '" & Replace$(TxtNat.Text, "'", "''") & "'"

strSQL = strSQL & ", Dtnato = '" & Replace$(TxtNasc.Text, "'", "''") & "'"

strSQL = strSQL & ", Pai = '" & Replace$(TxtPai.Text, "'", "''") & "'"

strSQL = strSQL & ", Mae = '" & Replace$(TxtMae.Text, "'", "''") & "'"

strSQL = strSQL & ", Posiçao = '" & Replace$(TxtPos.Text, "'", "''") & "'"

strSQL = strSQL & ", Numero = '" & Replace$(TxtNum.Text, "'", "''") & "'"

strSQL = strSQL & ", Complemento = '" & Replace$(TxtCompl.Text, "'", "''") & "'"

strSQL = strSQL & ", Civil = '" & Replace$(TxtCivil.Text, "'", "''") & "'"

strSQL = strSQL & ", Obsa = '" & Replace$(TxtObs.Text, "'", "''") & "'"

strSQL = strSQL & ", Cargo = '" & Replace$(Combo2.Text, "'", "''") & "'"

strSQL = strSQL & ", Classe = '" & Replace$(Combo3.Text, "'", "''") & "'"

strSQL = strSQL & ", Exercicio = '" & Replace$(Combo1.Text, "'", "''") & "'"

strSQL = strSQL & ", estado = '" & txtEstado.Text & "'"

strSQL = strSQL & ", cep = '" & txtCep.Text & "'"

strSQL = strSQL & ", TELRES = '" & strPhone & "'"

strSQL = strSQL & ", TELCEL = '" & strPhoneCel & "'"

strSQL = strSQL & " WHERE CustID = " & lngIDField

lvwCustomer.SelectedItem.Text = txtNOME.Text

PopulateListItem lvwCustomer.SelectedItem

End If

mobjCmd.CommandText = strSQL

mobjCmd.Execute

SetFormestado True

mblnUpdateInProgress = False

End Sub ]

O projeto esta disponível no link abaixo

http://www.4shared.com/file/103833037/fe79...va_incluso.html

Flecha

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Raphael,

Estive olhando os fóruns e achei o erro.

Estava na sequência de leitura na primeira parte da sub INSERT IN TO tem que coincidir com a segunda REPLACE na mesma ordem e não estava, dai o erro.

Consegui colocando a strsql = msgbox e ai comparei a atribuição de cad campo.

Obrigado

Flecha

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...