GetString Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: GetString Help

  1. #1
    Join Date
    Feb 2007
    Location
    Dorset, England
    Posts
    46

    Talking GetString Help

    I am having a problem geting data from my tables in Access 2000.
    I am using the rs.getstring() which returns all rows which is fine. After playing abit I started to use rs.getstring(,data.rsRADetail.AbsolutePosition,"|")
    which returned the first line but then when I called this again to get the second row, I got 2nd and 3rd row and called it again and got 4th and 5th ??? why does this happen ? why did I not get the 1st and 2nd the first time a Called this command ?
    I have called debug.print data.rsRADetail.AbsolutePosition and it shows 1 then 2 then 4. Can any one help me ??
    I can post my code if needed.

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    What is the value of data.rsRADetail.AbsolutePosition when you call GetString the first and second time? What is the row delimiter?
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #3
    Join Date
    Feb 2007
    Location
    Dorset, England
    Posts
    46
    When calling debug.print data.rsRADetail.AbsolutePosition for the first time it returns 1 (I have code before I call Getstring to make sure I am at 1st record) when called again it returns 2 BUT string value = Rows 2 & 3 call Getstring again debug.print ..... returns 4.
    I have tried Rowdelimiter as "*|" but still returns 2 rows and when running the rest of code to 'strip' the string it goes from the last row delimiter, so returns records 3 and 5 missing 2 & 4 ????

    Sorry for the messy code but I am still learning.

    Code:
    Public RARating, RAScore, RALike, RAControl,RAWorst,RAHazard as String
    
    Public Sub GetDataString(AssessName)
    Dim DataStop as Long
    Dim DataString as String
    Dim Variable as String
    
        Select Case AssessName
           Case "RA"
                data.rsRADetail.MoveFirst
    
                DataString = Data.rsRADetail.GetString(adClipString,,"|","*|")
                RARating = DataString
                Debug.Print DataString
                
                'DataStop = InStrRev(DataString,"|*")      
                'DataString = Left(DataString,Len(DataString) - 2)
                
                DataStop = InStrRev(DataString,"|")
                Variable = Right(DataString,Len(DataString) - DataStop)
                RARating = Variable
    
                DataStop = InStrRev(DataString,"|")
                Variable = Left(DataString,DataStop - 1)
                DataStop = InStrRev(Variable,"|")
                Variable = Right(Variable,Len(Variable) - DataStop)
                RAScore = Variable
    
                DataStop = InStrRev(DataString,"|")
                Variable = Left(DataString,DataStop - 1)
                DataString = Variable
                DataStop = InStrRev(Variable,"|")
                Variable = Right(Variable,Len(Variable) - DataStop)
                RALike = Variable
    
                DataStop = InStrRev(DataString,"|")
                Variable = Left(DataString,DataStop - 1)
                DataString = Variable
                DataStop = InStrRev(Variable,"|")
                Variable = Right(Variable,Len(Variable) - DataStop)
                RAControl = Variable
    
                DataStop = InStrRev(DataString,"|")
                Variable = Left(DataString,DataStop - 1)
                DataString = Variable
                DataStop = InStrRev(Variable,"|")
                Variable = Right(Variable,Len(Variable) - DataStop)
                RAWorst = Variable
    
                DataStop = InStrRev(DataString,"|")
                Variable = Left(DataString,DataStop - 1)
                DataString = Variable
                DataStop = InStrRev(Variable,"|")
                Variable = Right(Variable,Len(Variable) - DataStop)
                RAHazard = Variable
    
                Case Else
                
         End Select
    
    End Sub
    If anyone can tell me of an easier way to do this that will be good !
    Hope this helps, I can and willing to email Project to any one to have a look at.

    Thanks for help

  4. #4
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Parameters
    NumRows Optional. The number of rows to be converted in the Recordset. If NumRows is not specified, or if it is greater than the total number of rows in the Recordset, then all the rows in the Recordset are converted.

    As you see by the above clip from the GetString() documentation, that this parameter is the number of rows to return, so the first time AbsolutePosition was on record 1 so it returned 1 record, the next time AbsolutePosition would be 2 so you got 2 records, the next time AbsolutePosition would be 4 so you would get 4 records, etc...
    The AbsolutePosition returns your position within the list of records; but the parameter you passed it to was looking for how many records you wanted to retreive.
    If you want to process only one record at a time you should simply pass the value of 1 each time you call GetString(). Then you can use AbsolutePosition to see where you are and you can use EOF, or compare AbsolutePosition with RecordCount, to see when you reach the end.
    Last edited by Ron Weller; 02-07-2007 at 11:49 AM.

  5. #5
    Join Date
    Dec 2003
    Posts
    2,750
    I think Ron explained your results. What I'm wondering is why you are using GetString instead of:

    Code:
       RARating = data.rsRADetail.Fields(0).Value
       RAScore  = data.rsRADetail.Fields(1).Value
       RALike = data.rsRADetail.Fields(2).Value
       RAControl = data.rsRADetail.Fields(3).Value
       '...etc.
    GetString is really only useful for applying formatting to a Recordset as a whole, typically for display.
    Last edited by pclement; 02-07-2007 at 12:08 PM.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  6. #6
    Join Date
    Feb 2007
    Location
    Dorset, England
    Posts
    46
    Thanks Ron I thought RowNums was the row number to return not how may rows !!

    Paul - I had asked someone else on the net and they said use getstring() as it is really easy, I had started by doing it the way you have said but he was tell this was the best way.

    One thing I didn't say in my first post was once I have retrived the data I am then going to put it in a word document as the 'child' information which is the next bit I am stuck on.

    If I may ask this question as well, I have some code which write to word fine when it is the 'Parent' Information, but when I come to put the 'Child' info in it is a bit harder. The word document has been designed by someone else and then given to me to fill in the blanks, as it were.
    The Child info is split into 6 columns and I need to put the above data in to these columns.. Can any one throw some light on this one please

Similar Threads

  1. vb, GetString(), Word
    By Chris Yard in forum VB Classic
    Replies: 0
    Last Post: 02-05-2007, 05:45 AM
  2. Replies: 0
    Last Post: 03-04-2003, 10:07 AM
  3. ADO GetString
    By Mike Kenzie in forum authorevents.vaughn
    Replies: 1
    Last Post: 05-30-2000, 08:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center