Check wel of geen mailadres

Status
Niet open voor verdere reacties.

phobia

Terugkerende gebruiker
Lid geworden
4 sep 2006
Berichten
1.777
Ik heb het volgende code gebouwd, maar nu wil ik dat de code gestopt word als er geen mailadres is ingevoerd.

Code:
Function SendEmail(aanEmailAdres As String, onderwerp As String, TekstHTML As String, Bijlage As String)

Dim objMessage
Set objMessage = CreateObject("CDO.Message")


'==Onderwerp mail
objMessage.subject = onderwerp
'==Afzender mail
objMessage.From = """Paintball "" morphius.inc@upcmail.nl"
'==Ontvanger mail
objMessage.To = aanEmailAdres


'==Opzoeken van server gegevens.
server = Nz(DLookup("smtpserver", "tblServer"))
gebruiker = Nz(DLookup("gebruikersnaam", "tblServer"))
wachtwoord = Nz(DLookup("wachtwoord", "tblServer"))



'==Mail met HTML ody opmaken.
objMessage.HTMLBody = TekstHTML

'==Bijlage bij mail voegen.


'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = server

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = gebruiker

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = wachtwoord

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

'==Mail verzenden.
objMessage.Send

Set objMessage = Nothing
'==Bericht dat mail verzonden is.
 sErr = MsgBox("Verzonden aan " + aanEmailAdres, vbOKOnly, "Mail Verzonden.")
 
End Function

Wie kan en wilt mij verder helpen?
 
Het is een kwestie om te kijken of er wat ingevuld staat als mailadres.
In jouw code heb ik rood de aanvulling aangegeven. Je kan deze check ook al doen voordat je de functie aanroept.

Code:
Function SendEmail(aanEmailAdres As String, onderwerp As String, TekstHTML As String, Bijlage As String)

[COLOR="red"]If aanEmailAdres = "" then goto EINDE[/COLOR]

Dim objMessage
Set objMessage = CreateObject("CDO.Message")


'==Onderwerp mail
objMessage.subject = onderwerp
'==Afzender mail
objMessage.From = """Paintball "" morphius.inc@upcmail.nl"
'==Ontvanger mail
objMessage.To = aanEmailAdres


'==Opzoeken van server gegevens.
server = Nz(DLookup("smtpserver", "tblServer"))
gebruiker = Nz(DLookup("gebruikersnaam", "tblServer"))
wachtwoord = Nz(DLookup("wachtwoord", "tblServer"))



'==Mail met HTML ody opmaken.
objMessage.HTMLBody = TekstHTML

'==Bijlage bij mail voegen.


'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = server

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = gebruiker

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = wachtwoord

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

'==Mail verzenden.
objMessage.Send

Set objMessage = Nothing
'==Bericht dat mail verzonden is.
 sErr = MsgBox("Verzonden aan " + aanEmailAdres, vbOKOnly, "Mail Verzonden.")

[COLOR="Red"]EINDE:[/COLOR]
 
End Function

Mvg. René
 
thnx, ik wist dat ik een if functie moest doe, maar niet hoe en waar

ben ook een autodydact
 
Deze fout treedt op als een gebeurtenis niet is uitgevoerd omdat Microsoft Office Access de locatie van de logica voor de gebeurtenis niet kan beoordelen. Een voorbeeld: als de eigenschap OnOpen van de vorm is ingesteld op =[Field] doet deze out zich voor omdat Access verwacht dat er een macro of gebeurtenisnaam wordt uitgevoerd wanneer de gebeurtenis wordt geactiveerd.

Deze fout is het gevolg!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan