Avatar billede t-johansen Juniormester
23. marts 2006 - 12:55 Der er 10 kommentarer og
1 løsning

Hjælp til regel: IF "ikke eksisterer" then msgbox"bla bla" exit

Nu starter vi helt forfra.... Point værdi er steget til 100 som går til den der kan give mig en komplet løsning.

Håber i kan hjælpe mig. Hvis i mangler flere info så sig til.

Vigtigt:
MyEmailAddress er en forespørgsel over tabelen dbo_VEHICLE som har Feltet REGISTER_NUMBER som her skal søges på.


Skal bruge en "IF "regnr ikke eksistere i"...Then...msgbox"mangler bla bla"...exit function, Else" kode i 2 punkter af min kode.

Første sted (har forsøgt med hjælp herfra men virker ikke):
-------------------------------------------------------------------
  Regnr = InputBox("Indtast kundens registerings nummer")

If DCount(dbo_VEHICLE.REGISTER_NUMBER, MyEmailAdresses, "REGISTER_NUMBER Like '" & UCase(Regnr) & "'") = 0 Then

MsgBox "Registreringsnummer ikke fundet"
Exit Function

Else
------------------------------------------------------------------


Det andet sted (hvor "LAST_SERVICE_TXT" skal være større end nul):
-----------------------------------------------------------
Set MyMail = MyOutlook.CreateItem(olMailItem)
     
     
     
         
            ' This addresses it
            MyMail.To = MailList("LAST_SERVICE_TXT")
----------------------------------------------------------










Den komplete kode:
-------------------------------------------------------------


Option Compare Database
Option Explicit
' You need to declare a reference to the Outlook library, and the filesystemobject.
' this is not as hard as it sounds.
'
' Look in the menu above, and click Tools, then select References
'
' Scroll down the list until you see
' Microsoft Scripting Runtime -- and put a check next to it (if one is not there already)
'
' Microsoft Outlook Object Library -- check that.
'          There will be some version number there as well; it doesn't matter.
'          This will work with Outlook98 and Outlook2000 and OutlookXP.  It hasn't been tested on Outlook 2003 yet.


Public Function SendEMail()

Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim Regnr As String



Set fso = New FileSystemObject



  ' Now, we open Outlook for our own device..
    Set MyOutlook = New Outlook.Application


' Set up the database and query connections

    Set db = CurrentDb()
 
 
 
    Regnr = InputBox("Indtast kundens registerings nummer")

If DCount(dbo_VEHICLE.REGISTER_NUMBER, MyEmailAdresses, "REGISTER_NUMBER Like '" & UCase(Regnr) & "'") = 0 Then

MsgBox "Registreringsnummer ikke fundet"
Exit Function

Else
 
   
    Set MailList = db.OpenRecordset("SELECT * FROM MyEmailAddresses WHERE dbo_VEHICLE.REGISTER_NUMBER Like '" & UCase(Regnr) & "'")

' now, this is the meat and potatoes.
' this is where we loop through our list of addresses,
' adding them to e-mails and sending them.

    Do Until MailList.EOF

        ' This creates the e-mail
     
        Set MyMail = MyOutlook.CreateItem(olMailItem)
     
     
     
         
            ' This addresses it
            MyMail.To = MailList("LAST_SERVICE_TXT")
     
         
            'This gives it a subject
            MyMail.Subject = Subjectline$
         
            'This gives it the body
            MyMail.Body = MyBodyText


         

            ' To briefly describe:
            ' "c:\myfile.txt" = the file you want to attach
            '
            ' olByVaue = how to pass the file.  olByValue attaches it, olByReference creates a shortcut.
            '      the shortcut only works if the file is available locally (via mapped or local drive)
            '
            ' 1 = the position in the outlook message where to attachment goes.  This is ignored by most
            '      other mailers, so you might want to ignore it too.  Using 1 puts the attachment
            '      first in line.
            '
            ' "My Displayname" = If you don't want the attachment's icon string to be "c:\myfile.txt" you
            '      can use this property to change it to something useful, i.e. "4th Qtr Report"



            'This sends it!
            'MyMail.Send'

            'Some people have asked how to see the e-mail
            'instead of automaticially sending it.
            'Uncomment the next line
            'And comment the "MyMail.Send" line above this.

            MyMail.Display


     
    'And on to the next one...
    MailList.MoveNext
 
End If
 
Loop


'Cleanup after ourselves

Set MyMail = Nothing


'Uncomment the next line if you want Outlook to shut down when its done.
'Otherwise, it will stay running.

'MyOutlook.Quit
Set MyOutlook = Nothing

MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing

End Function
Avatar billede terry Ekspert
23. marts 2006 - 13:55 #1
If DCount("REGISTER_NUMBER", "MyEmailAdresses", "REGISTER_NUMBER Like '" & UCase(Regnr) & "'") = 0 Then
Avatar billede t-johansen Juniormester
23. marts 2006 - 14:10 #2
Damn you, you're my god....


Point til dig.

så kan jeg endelig komme videre.
Avatar billede t-johansen Juniormester
23. marts 2006 - 14:38 #3
Dcount er det kun på bogstaver?

fordi her laver jeg samme kriterie men på sms nr og her siger den heletiden den er nul.

If DCount("NEXT_SERVICE_TXT", "MyEmailAddresses", "NEXT_SERVICE_TXT Like '" & "'") = 0 Then
        MsgBox "Ingen SMS nummer"
            Exit Function

        Else
Avatar billede terry Ekspert
23. marts 2006 - 15:05 #4
Dcount counts the number of records matching the criteria.

"NEXT_SERVICE_TXT Like '*" & "And you need something here" &  "*'")

or

"NEXT_SERVICE_TXT =  '" & "And you need something here" & "'")
Avatar billede t-johansen Juniormester
24. marts 2006 - 11:19 #5
okay troede jeg havde lært noget men fatter det ikke helt.

Har lavet denne, som skal vise beskeden hvis der er færre bogstaver end 3.

Hvad er der lige galt her?


kode
---------------------------------------


Dim emailadr As String

emailadr = ("")
        If DCount("LAST_SERVICE_TXT", "MyEmailAddresses", "LAST_SERVICE_TXT Like '*" & (emailadr) & "*'") <= 3 Then
   
            MsgBox "Ingen e-mail adresse, indtast først en email adresse"
        Exit Function

        Else

.....resten af koden indtil.....
end if
Avatar billede t-johansen Juniormester
24. marts 2006 - 12:05 #6
Har prøvet disse to.

Den første kommer den frem med msgboks selvom der står noget i LAST_SERVICE_TXT

Den anden kommer ikke frem med msgbox selvom der ikke står noget i LAST_SERVICE_TXT


første:
---------------------------------------
If DCount("LAST_SERVICE_TXT", "MyEmailAddresses", "LAST_SERVICE_TXT = ' * '") = 0 Then
   
            MsgBox "Ingen e-mail adresse, indtast først en email adresse i Dracar+, M100 under værkstedsoplysninger"
        Exit Function

        Else
-----------------------------------------

anden:
------------------------------------
If DCount("LAST_SERVICE_TXT", "MyEmailAddresses", "LAST_SERVICE_TXT = ' * '") < 0 Then
   
            MsgBox "Ingen e-mail adresse, indtast først en email adresse i Dracar+, M100 under værkstedsoplysninger"
        Exit Function

        Else
----------------------------------------
Avatar billede t-johansen Juniormester
24. marts 2006 - 13:18 #7
dooh har fattet det nu!

men har stadig problemet, ved bare det ikke skal løses på denne måde.

Jeg skal lave en IF sætning som skal kontrollere om feltet LAST_SERVICE_TXT indeholder tekst, hvis det gør skal den fortsætte

hvad hedder den formel?
Avatar billede t-johansen Juniormester
24. marts 2006 - 13:35 #8
kan man brgue denne ?

If IsNull("LAST_SERVICE_TXT") Then
       
          MsgBox "Ingen e-mail adresse, indtast først en email adresse"
        Exit Function
        Else
Avatar billede t-johansen Juniormester
24. marts 2006 - 14:10 #9
løst med:

If MailList("LAST_SERVICE_TXT") > 0 Then
Avatar billede terry Ekspert
24. marts 2006 - 14:20 #10
Sorry, didnt see your comments, busy working :o)

Is it all working now, if not drop a comment and I'll see what I can do.
Avatar billede t-johansen Juniormester
24. marts 2006 - 14:27 #11
yes got i working :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester