Results 1 to 7 of 7
  1. #1
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    36

    Function>Reference to recordset field>Debug.Print doesn't show field value

    Hello!

    I've been pulling my hair out trying to get this function to, well, FUNCTION (grin)

    What am I doing wrong?
    "Activities" fields are "ShortProgram", type is Short Text, "ProgramNumber", type is Number.

    Code:
    Public Function deleteLeadingCharacters()
    Dim db As Database
    Dim rs As Recordset
    Dim strSql As String
    Dim Program As String
    Dim ShortProgram As String
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Activities")
    
    rs.MoveFirst
    
    Do Until rs.EOF
        Debug.Print "ShortProgram " & rs!ShortProgram
        Program = Mid(rs!ShortProgram, 29)
        Debug.Print "Program= " & Program
        rs.Edit
        rs!ShortProgram = Program
        rs.Update
        If rs.EOF Then Exit Do
    
    Loop
    rs.Close
    End Function
    Immediate window shows;
    ShortProgram and
    Program

    Thanks in advance. A helpful answer will get you a joke.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    You are not moving to next record?
    Plus no need for exit, as you have that as your loop?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If your rs is empty, Move anything will raise an error. There are better ways - I use what Allen Browne wrote:
    If Not (rs.EOF And rs.BOF) Then

    Also, should really declare your ADO/DAO libraries where applicable: Dim rs As DAO.Recordset (or the other)
    Can hardly wait for the joke!
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    In addition to the other comments, suggest show some content- you first debug implies that rs!shortprogram is the 3 letter word ‘and’ so way less than 29 characters so your mid function won’t return anything

  5. #5
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    36
    Okay, pointed me in the right direction...
    Here's the joke.
    Three dogs are in the doggie bar having a drink.
    There's a Husky, a Doberman and a Chihuahua
    In walks a foxy-looking Collie who says: "whichever one of you three can use the words 'liver' and 'cheese' most creatively can have a date with me"
    The Husky says "I love liver and cheese"
    The Doberman says "I hate liver and cheese"
    The Chihuahua says, in his best Taco Bell accent, says "liver alone, cheese mine"

    Get it?
    Last edited by Budatlitho; 03-24-2023 at 06:11 AM. Reason: Constructive editing advised by Micron

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Ya mean "Liver alone, cheese mine"?
    I laughed anyway!
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    36
    Yes, well, it’s normally told by word of mouth……

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

Similar Threads

  1. Replies: 1
    Last Post: 02-15-2020, 12:38 PM
  2. Replies: 5
    Last Post: 01-20-2018, 03:40 PM
  3. DAO recordset field reference syntax
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 04-23-2016, 06:02 PM
  4. Pass recordset field into function
    By Ruegen in forum Programming
    Replies: 6
    Last Post: 04-13-2014, 11:04 PM
  5. Replies: 3
    Last Post: 01-31-2014, 09:13 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