Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
#42331
Boa noite. Estou precisando de uma ajuda. Tenho uma Userform com algumas textbox de preenchimento obrigatório e outras não. Então quando clico no botão para salvar os dados digitados, mas uma destas textbox de preenchimento obrigatório está vazia, obviamente aparece uma mensagem solicitando o seu preenchimento e assim por diante. No entanto, tenho uma textbox (Plano) onde tenho duas opções de preenchimento: "Particular" ou "Convênio" e quando digitado "Particular" eu não preciso preencher a próxima textbox (Nº Carteira) para salvar os dados, mas se eu digitar "Convênio" gostaria que fosse obrigatório o preenchimento do nº da carteira na próxima textbox. Com o código que coloquei mesmo após digitar "Convênio" e o nº da Carteira, ao clicar no botão salvar ele continua pedindo para digitar o nº da carteira. Alguém poderia me ajuda? Desde já obrigado!
Segue parte do meu código:

Private Sub CmdSalvar_Click()

If WorksheetFunction.CountIf(Range("C9:C1923"), txtNome.Value) > 0 And txtNome <> "" Then
MsgBox "Esse cadastro já existe!", vbCritical, "ERRO"
Exit Sub

Else

If txtNome.Text = "" Then
MsgBox "Digitar o nome do paciente", vbExclamation, "AVISO"
txtNome.SetFocus
Exit Sub
End If

If txtDDD.Text = "" And txtTelefone1.Text = "" Then
MsgBox "Digitar o DDD e o Nº de Telefone", vbExclamation, "AVISO"
txtDDD.SetFocus
Exit Sub
End If

If txtTelefone1.Text = "" Then
MsgBox "Digitar o Nº de Telefone", vbExclamation, "AVISO"
txtTelefone1.SetFocus
Exit Sub
End If

If txtPlano.Text = "" Then
MsgBox "Digitar se Convênio ou Particular", vbExclamation, "AVISO"
txtPlano.SetFocus
Exit Sub
End If

If txtPlano.Text = "PARTICULAR" Then
End If

If txtPlano.Text = "CONVÊNIO" Then
MsgBox "Digitar o Nº da Carteira", vbExclamation, "AVISO"
txtNºCarteira.SetFocus
Exit Sub
End If

If txtPlano.Text = "CONVÊNIO" And txtNºCarteira.Text <> "" Then
End If
End If

' Restante do código
End Sub
#42532
Olá,

Substitua essas linhas de código:
Código: Selecionar todos
If txtPlano.Text = "CONVÊNIO" Then 
MsgBox "Digitar o Nº da Carteira", vbExclamation, "AVISO"
txtNºCarteira.SetFocus
Exit Sub
End If

If txtPlano.Text = "CONVÊNIO" And txtNºCarteira.Text <> "" Then 
End If
End If
por essas:
Código: Selecionar todos
If txtPlano.Text = "CONVÊNIO"  And txtNºCarteira.Text = "" Then 
MsgBox "Digitar o Nº da Carteira", vbExclamation, "AVISO"
txtNºCarteira.SetFocus
Exit Sub
End If
Qualquer dúvida poste novamente no fórum.

Abraço!
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord