Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Feb 2004
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Writing an Access field value to an *.ini file, de (Access 2002)

    Hi, I have an Access database.

    From Word 2002, I want to search the database, look for a record where the field "HomeOffice" is equal to a string variable. Then retrive the data from another field from that particular record, and write the data to an *.ini file.

    I have the following code so far:

    dim DBInfo as dao.database
    Dim rstInfo as dao.recordset
    Dim Str_SQLNetwork as string

    strHomeOffice = SystemPrivateProfile ...etc........ "HomeOffice" - this sets the variable, and this works fine.

    Set dbInfo = dao.opendatabase ("c:database.mdb")
    Set rstInfo = dbInfo.openrecordset("tblInfo")

    Str_SQLNetwork = "SELECT tblInfo.[NetworkDocPath] FROM fblInfo WHERE tblInfo.[HomeOffice] = " & strHomeOffice & ";"

    WritePrivateProfileString ..... etc. to the *.ini file section.


    The string variable is returned OK usring the strHomeOffice variable. The problem I have is that I can't get it to actually return the data from the NetworkDocPath field . I have used WritePrivateProfileString a few times without any problem. How do I actually return the data of the NetworkDocPath field for that particular record (where the HomeOffice = the string variable)?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Writing an Access field value to an *.ini file, de (Access 2002)

    Try this:

    ...
    Dim strPath As String
    ...
    Set dbInfo = DAO.OpenDatabase ("c:database.mdb")
    ' SQL statement
    str_SQLNetwork = "SELECT NetworkDocPath FROM tblInfo WHERE HomeOffice = " & Chr(34) & strHomeOffice & Chr(34)
    ' Open recordset on SQL statement
    Set rstInfo = dbInfo.OpenRecordset(str_SQLNetwork)
    ' Retrieve field from recordset
    strPath = rst!NetworkDocPath
    ' Write to ini file - substitute the appropriate names
    System.PrivateProfileString("C:Test.ini", "Paths", "DocPath") = strPath

  3. #3
    Lounger
    Join Date
    Feb 2004
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Writing an Access field value to an *.ini file, de (Access 2002)

    Hi, thanks for this and sorry for the delay in posting this back: The code I actually used in the end was as follows, which works perfectly:

    strHomeOffice = System.privateprofilestring (GetIniFile, "CurrentInfo", "HomeOffice")

    set dbInfo = dao.opendatabase ("c:database.mdb")

    ' SQL statement
    strSQL_SQLNetworkDocPath = "SELECT NetworkDocPath FROM tblInfo WHERE HomeOffice = '" & strHomeOffice & "';"

    'Open recordset on SQL statement
    Set rstNetworkDocPath = dbInfo.openrecordset(strSQL_NetworkDocPath, dbOpenDynaset)

    'Set string values for above recordset
    strNetworkDocPath = rstNetworkDocPath("NetworkDocPath")

    'Write to ini file (GetInifile function already given in a seperate function)

    WritePrivateProfileString "Current_Info", "NetworkDocPath", strNetworkDocPath, GetIniFile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •