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

    problem to build vba code

    I greet all the friends of the forum,




    I would like the help of more experienced friends about the conversion of the code below:


    I have the table "tempSVN" which has a Number field. I would like to add into the same table also the fields "svnID" (Autonumber) and "DateAdded" (short date format). As you may understand this is not the problem for me, but the problem is the following code which is runing for the moment and is taking only the value of the "S". I would like to add also the svnID and the DateAdded into a table "tempSVN"

    Public Function CheckVolumeSerialNumber()
    Dim S, strCheck0, strCheck1, strCheck2, strCheck3, strCheck4 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 = Serial

    ' I would like when i'm running the query to add also the new fields (svnID and DateAdded)
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO tempSVN VALUES ('" & S & "')"
    DoCmd.SetWarnings True

    End Function

    Can anybody help?

    Thanks in advanced

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am not familiar with GetVolumeInformation. I am not finding any examples for entry points for svnID and DateAdded. Not even sure what svnID is anyway. What is it you are doing with Serial?

    Maybe something like Attributes will manage what you need.
    https://www.accessforums.net/program...tml#post237647

  3. #3
    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
    gstylianou,

    Where did you find that code? What exactly do you want to do in plain English -no vba?

    This statement
    Dim S, strCheck0, strCheck1, strCheck2, strCheck3, strCheck4 As String

    does NOT do what you think. In Access you must explicitly dim the variable with a datatype. If you do not declare the datatype, the default assignment is variant.

    So for each of your variables to be strings, you need something like:

    Dim S as string
    Dim strCheck0 as string.... OR
    Dim S as string, strCheck0 as string....

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

    With this code you can read the Hard Disc Serial Number. Is working fine...

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Your INSERT statement looks incomplete. It doesn't identify the field to populate. Use Execute method and SetWarnings not needed.

    How does Serial get populated?

    If svnID is an autonumber field, no need to include in the INSERT statement.

    CurrentDb.Execute "INSERT INTO tempSVN([field for S value], DateAdded) VALUES ('" & S & "', Date())"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Good morning June7 from Cyprus,

    let me try your example and i will let you know

    Thanks in advanced

  7. #7
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    June7 I would like to thank you very much for your help.

    Another one issue....! With this code is working fine but i need each time i'm running the code i need to going to "Record,,New" ( i mean the "SvnNumber" field which is on tblSVN)

    Is that possible man?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't understand the question.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

    Thank you very much for your interest to help. The issue has been solved with your code.

    Thanks again.

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

Similar Threads

  1. Replies: 10
    Last Post: 07-04-2014, 12:29 AM
  2. Code problem
    By sboelitz in forum Programming
    Replies: 1
    Last Post: 06-15-2012, 08:35 AM
  3. Problem with Code
    By jackiea in forum Programming
    Replies: 1
    Last Post: 10-07-2011, 05:59 PM
  4. Code Problem
    By Jeddell in forum Programming
    Replies: 2
    Last Post: 09-29-2011, 06:31 PM
  5. Problem with Code
    By cujee75 in forum Programming
    Replies: 0
    Last Post: 03-10-2006, 02:40 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