Results 1 to 6 of 6
  1. #1
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167

    Problem with code which includes many IF

    Good morning,


    I am having a strange problem where really I can not find the edge of what it can be the problem. The problem is as follows:


    I have the following vba code which serves essentially to find the serial number of the computer's hard disc. When the code find the serial number then can be avaliable as "S" to use it as you may want.




    Now, if you assign any Pc as the "Administrator" (through the vba code) after the verification of the serial number the code should by-pass all relevant procedures and proceeds directly to open the form "frmStartupScreen".


    The Problem:
    Although the code works, sometimes (not always) after the opening of the database cannot show the relevant messages ( eg. "Welcome Administrator" if the code recognize the Pc as the administrator) and leaves the empty the screen (blue screen environment access) and i must do even a click anywhere in order to show the relative messages so to be able to Login the database.


    Is it something related to my computer ? Maybe it would be better instead of the code "IF" to change it with "Case" ? If with "Case" should be better, can anyone help in order to do that?


    Regards

    .................................................. .................................................. ..................................................

    Public Function CheckVolumeSerialNumber1()
    Dim S, Serial As Long, VName As String, FSName As String, strSQL As String

    VName = String$(255, Chr$(0))
    FSName = String$(255, Chr$(0))

    GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
    VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
    FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
    Serial = Replace(Trim(Str$(Serial)), "-", "")

    ' εύρεση σειριακού αριθμού του υπολογιστή και δήλωση του ώς S
    S = Serial

    Dim SVNnumber As String
    Dim sSQL As String
    'Wipe the existing data from tblSVN
    sSQL = "DELETE * FROM tblSVN;"
    CurrentDb.Execute sSQL, dbFailOnError

    If S = 2032771935 And Forms!MasterForm.FirstInstallation = True Then
    MsgBox "CheckVolumeSerialNumber1 - Welcome adninistrator", vbExclamation, "Administrator Login"
    Forms!MasterForm.SVNA = S
    Forms!MasterForm.Pc3 = True
    DoCmd.OpenForm "frmStartupScreen"
    End If

    If S <> 2032771935 And Forms!MasterForm.FirstInstallation = True Then

    strSQL = "INSERT INTO tblSVN (SvnNumber,DateAdded) VALUES(" & _
    Serial & ", #" & Format(Now(), "m/d/yyyy mm:ss") & "#)"
    CurrentDb.Execute (strSQL)
    Forms!frmSVN.Refresh
    MsgBox "Παρακαλώ καταχωρείστε τα προσωπικά σας στοιχεία ", vbInformation, "Νέος χρήστης"
    DoCmd.OpenForm "frmAddOwner", acNormal
    End If

    If S = 2032771935 And Forms!MasterForm.TrialMode = True Then
    MsgBox "CheckVolumeSerialNumber1 - Welcome adninistrator", vbExclamation, "Administrator Login"
    Forms!MasterForm.SVNA = S
    Forms!MasterForm.Pc3 = True
    Forms!MasterForm.Refresh
    DoCmd.OpenForm "frmStartupScreen"
    End If
    ' Else
    If S <> 2032771935 And Forms!MasterForm.TrialMode = True Then
    strSQL = "INSERT INTO tblSVN (SvnNumber,DateAdded) VALUES(" & _
    Serial & ", #" & Format(Now(), "m/d/yyyy mm:ss") & "#)"
    CurrentDb.Execute (strSQL)
    Forms!frmSVN.Refresh
    Forms!MasterForm.Refresh
    ExistSN

    End If

    End Sub

    .................................................. .................................................. .................................................. ...........................

    Regarding the "ExistSN"

    Public Sub ExistSN()

    Dim SN As Variant
    SN = DLast("SvnNumber", "tblSVN")

    If Not IsNull(SN) Then
    If DCount("*", "tblLogSVN", "SvnNumber=" & SN) Then
    MsgBox " ExistSN - Έχετε δικαίωμα χρήσης σε αυτόν τον υπολογιστή.", vbInformation, "Sports and Nutrition Management System. SN " & SN & " Υπάρχει."
    DoCmd.OpenForm "frmTrialLogin"
    DoCmd.Close acForm, Me.Name

    Else
    If MsgBox("Wrong ExistSN - Μή εξουσιοδοτημένος υπολογιστής", vbYesNo + vbExclamation, " SN " & SN & " - Ακυρο SVN") _
    = vbYes Then
    DoCmd.OpenForm "frmAddSVN"
    ' DoCmd.Close acForm, Me.Name
    Else
    DoCmd.OpenForm "Form1"
    DoCmd.Close acForm, Me.Name
    ' End If
    End If
    End If
    End If
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    comment out the DoCmd.Close acForm, Me.Name
    it can sometimes do the wrong thing.

    If still a problem, do you use a remote connection app, like Citrix?

  3. #3
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Hello ranman256

    I did tha my friend. Still the same issue. Not, i'm not using any remote connection...!

    Do you have any idea what going wrong? If we will try with Case would be better you think

    Regards

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the code, "S" is declared as a Variant, not a Long Integer. You must explicitly declare S as a Long like this:
    Dim S As Long, Serial As Long, ...
    ------------
    Also, you have

    strSQL As String and
    sSQL As String

    but only use sSQL
    Doesn't hurt, but it is an unused variable..
    ------------

    I had trouble following the flow, so I re-wrote the function. Using IF()'s is fine.
    See if this helps you find your problem.

    Code:
    Public Function CheckVolumeSerialNumber1()
        Dim S, Serial As Long, VName As String, FSName As String, strSQL As String
        Dim SVNnumber As String
        Dim sSQL As String
    
        VName = String$(255, Chr$(0))
        FSName = String$(255, Chr$(0))
    
        GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
        VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
        FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
        Serial = Replace(Trim(Str$(Serial)), "-", "")
    
        ' ?????? ????????? ??????? ??? ?????????? ??? ?????? ??? ?? S
        S = Serial
    
        'Wipe the existing data from tblSVN
        sSQL = "DELETE * FROM tblSVN;"
        CurrentDb.Execute sSQL, dbFailOnError
    
        If S = 2032771935 Then
            If Forms!MasterForm.FirstInstallation = True Then
                MsgBox "CheckVolumeSerialNumber1 - Welcome adninistrator", vbExclamation, "Administrator Login"
            End If
    
            If Forms!MasterForm.TrialMode = True Then
                MsgBox "CheckVolumeSerialNumber1 - Welcome adninistrator", vbExclamation, "Administrator Login"
            End If
    
            'common to the previous IF() functions
            Forms!MasterForm.SVNA = S
            Forms!MasterForm.Pc3 = True
            Forms!MasterForm.Refresh
            DoCmd.OpenForm "frmStartupScreen"
    
        Else  ' S <> 2032771935
    
            'common to the following IF() statements
            strSQL = "INSERT INTO tblSVN (SvnNumber,DateAdded) VALUES(" & _
                     Serial & ", #" & Format(Now(), "m/d/yyyy mm:ss") & "#)"
            CurrentDb.Execute (strSQL)
            Forms!frmSVN.Refresh
    
    
            If Forms!MasterForm.FirstInstallation = True Then
                MsgBox "???????? ???????????? ?? ????????? ??? ???????? ", vbInformation, "???? ???????"
                DoCmd.OpenForm "frmAddOwner", acNormal
            End If
    
            If Forms!MasterForm.TrialMode = True Then
                Forms!MasterForm.Refresh
                ExistSN
            End If
    
        End If
    
    
    End Function
    Have you set a break point and stepped through the code?

    BTW, in the message boxes, the first "administator" is misspelled. You have "Welcome adninistrator"

  5. #5
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Good morning all

    Steve thank you very much for your help. I will try later today to check your code and i will let you know about...

    Thanks again

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Another way to get drive serial number. You must set a reference to the Microsoft Scripting Runtime

    Code:
    Sub driveStuff()
    
        Dim FSO As New Scripting.FileSystemObject
        Dim drvVolume As Drive
            
          Set drvVolume = FSO.GetDrive("C")
          Debug.Print drvVolume.SerialNumber
         
    End Sub

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

Similar Threads

  1. Replies: 3
    Last Post: 09-22-2014, 04:38 PM
  2. Need ideas for email survey that includes pictures of employees
    By Gina Maylone in forum Database Design
    Replies: 3
    Last Post: 12-27-2013, 02:58 PM
  3. Replies: 3
    Last Post: 07-13-2013, 12:11 AM
  4. Macro to open a report that includes certain dates?
    By hartandsoul85 in forum Access
    Replies: 2
    Last Post: 05-11-2012, 11:47 AM
  5. Copying fields includes column name
    By julioot in forum Access
    Replies: 14
    Last Post: 04-04-2012, 08:25 AM

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