Results 1 to 7 of 7
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Consistensy



    Code:
    Private Sub cmdMailTicket_Click()
        On Error GoTo Err_cmdMailTicket_Click
    
        Dim stWhere As String       '-- Criteria for DLookup
        Dim varTo As Variant        '-- Address for SendObject
        Dim stText As String        '-- E-mail text
        Dim RecDate As Variant      '-- Rec date for e-mail text
        Dim stSubject As String     '-- Subject line of e-mail
        Dim stTicketID As String    '-- The ticket ID from form
        Dim stWho As String         '-- Reference to tblUsers
        Dim stHelpDesk As String    '-- Person who assigned ticket
        Dim strSQL As String        '-- Create SQL update statement
        Dim errLoop As Error
    
        '-- Combo of names to assign ticket to
        stWho = Me.cboAssignee
        stWhere = "tblUsers.strUserID = " & "'" & stWho & "'"
        '-- Looks up email address from TblUsers
        varTo = DLookup("[strEMail]", "tblUsers", stWhere)
    
        stSubject = ":: New Help Desk Ticket ::"
    
        stTicketID = Format(Me.txtTicketID, "00000")
        RecDate = Me.txtDateReceived
        '-- Helpdesk employee who assigns ticket
        strHelpDesk = Me.cboReceivedBy.Column(1)
    
    
        stText = "You have been assigned a new ticket." & Chr$(13) & _
                 Chr$(13) & "Ticket number: " & stTicketID & Chr$(13) & _
                 "This ticket has been assigned to you by: " & strHelpDesk & _
                 Chr$(13) & "Received Date: " & RecDate & Chr$(13) & _
                 Chr$(13) & "This is an automated message." & _
               " Please do not respond to this e-mail."
    
        'Write the e-mail content for sending to assignee
        DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1
    
        'Set the update statement to disable command button
        'once e-mail is sent
        strSQL = "UPDATE tblHelpDeskTickets " & _
                 "SET tblHelpDeskTickets.ysnTicketAssigned = -1 " & _
                 "Where tblHelpDeskTickets.lngTicketID = " & Me.txtTicketID & ";"
    
    
        On Error GoTo Err_Execute
        CurrentDb.Execute strSQL, dbFailOnError
        On Error GoTo 0
    
        'Requery checkbox to show checked
        'after update statement has ran
        'and disable send mail command button
        Me.chkTicketAssigned.Requery
        Me.chkTicketAssigned.SetFocus
        Me.cmdMailTicket.Enabled = False
    
        Exit Sub
    
    Err_Execute:
    
        ' Notify user of any errors that result from
        ' executing the query.
        If DBEngine.Errors.Count > 0 Then
            For Each errLoop In DBEngine.Errors
                MsgBox "Error number: " & errLoop.Number & vbCr & _
                       errLoop.Description
            Next errLoop
        End If
    
        Resume Next
    
    
    Exit_cmdMailTicket_Click:
        Exit Sub
    
    Err_cmdMailTicket_Click:
        MsgBox Err.Description
        Resume Exit_cmdMailTicket_Click
    
    End Sub
    The code that I posted above was found online. It could be very useful to me. The main fault that I have with it is I believe that
    there are some rather obvious errors in the code. The first is

    stHelpDesk

    or

    Dim stHelpDesk As String

    in the dimension variable area. It is a variable so they can name it anything that they want.
    However, once they name it, they must be consistent and I believe that they fell down here.

    The first time that they use it in the code they use

    Dim strHelpDesk As String

    instead. Now I am quite sure that is wrong.

    I am also uncertain as to why they even used st instead of str on a string laziness?

    Any help appreciated. Thanks in advance.


    Respectfully,

    Lou Reed

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Maybe miskey, just take the "r" out in the code line. Did you try to run it? Are you getting errors?

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Yes, I did get errors when I tried to run it. It seems that there is considerable miskey-ing in this example.

    R,

    Lou Reed

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    This is why you're only asking for trouble if you do not have Option Explicit at the top of every module, along with the default Compare property setting. A compile will catch every non-declared variable (mis-spelled or not). st is not lazy - it's the author's predicate for a string variable; it's just not mine anymore than "t" is mine for a table, which you can find in posts from knowledgeable posters in this forum. The important thing is to adopt a naming convention and stick with it as much as possible. If you can read cmbDept or stWhere and know that the first is a combo and the second a string, the author has successfully communicated the type even if your habit is cboDept and strWhere.

    When you're trouble shooting and get a long way down into a procedure and look at what's happening with a variable (e.g. RecDate), you might be going back to find out what type it is. So not only does the author mis-type one or more variables, a convention is not consistently used (varRecDate). On that note, I usually will not bother to write strSql as opposed to simply sql because I take the position that if you're reading my code, you ought to know that a sql statement can only be a string, otherwise you shouldn't be poking around in it (unless of course, it's in response to a forum post).

    P.S. if you're thinking of nit picking, ok, a sql statement can be a variant too, but who would do that on a regular basis?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I have the whole db downloaded as an *.mdb file. I want to convert it to an MS Access *.accdb file. I click on this file in MS Access 2010.

    Then I start to convert it to an *.accdb db. When I click it to save as it says an *.accdb it says that I must close all objects before conversion.

    Do you wan to close objects now : yes or no? I click yes.

    Then I get an option to save the file, but the only option format is still *.mdb, not accdb. What gives.

    It seems that it is certain to work once all of the object have been closed; but once that is done then it opens a box and says save the db
    only as *.mdb.

    That is not what I want.

    How to save an *.mdb db file as an *.accdb file?

    Thanks in advance.

    Respectfully,

    Lou reed

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I got this. I was pressing the wrong keys. That is why it did not work.

    Thanks anyway.


    Respectfully,

    Lou Reed

  7. #7
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I do have Options Explicit on my code. That is not the issue.

    R,

    Lou Reed

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums