Results 1 to 3 of 3
  1. #1
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164

    Setting ubound textbox value in Report

    Hi Everyone,



    I'm having some difficulty setting values for some unbound text boxes on a report of mine using VBA. Doing a quick search of various Access programming sites, everyone seems to be suggesting the straightforward code: Me.myTextBox.Value = x. Unfortunately when I use this plain and simple approach I receive the dreaded run time error 2448 - 'You can't assign a value to this object'. The code I am using is posted below and I would appreciate any thoughts any of you may have.

    Code:
    Private Sub Report_Open(Cancel As Integer)
        Dim myARPTID As Integer, strSQL As String, strRST As String, rst As DAO.Recordset, AccTitle(5) As String, AccType(3) As String
        Dim AccSum(5) As String, DateAcc(5) As Date, i As Integer
        
        'Getting the specific Annual Report ID for selecting the list of accomplishments
        myARPTID = Forms![ARPT-CA].fARPTID
        Debug.Print myARPTID
        
        strSQL = "SELECT PartInfo.[Participant Name], ARPT.AProfGoal, PartInfo.Cohort, PartInfo.[Sponsoring Service]," & _
                 " PartInfo.[STEM Discipline], ARPT.APRTID" & _
                 " FROM PartInfo INNER JOIN ARPT ON PartInfo.[Smart Id] = ARPT.SMARTID" & _
                 " WHERE (((ARPT.APRTID)=" & myARPTID & "));"
    
            Me.RecordSource = strSQL
        ' Getting any accomplishments for this participant
        strRST = "SELECT ARACC.AccTitle, ARACC.DateAcc, ARACC.AccType, ARACC.AccSum" & _
                 " FROM ARPT INNER JOIN ARACC ON ARPT.APRTID = ARACC.ARPTID" & _
                 " WHERE (((ARPT.APRTID)=" & myARPTID & "))"
        
        Set rst = CurrentDb.OpenRecordset(strRST)
        
         ' Looping through potential accomplishments and assigning them to arrays
        i = 1
        Do Until rst.EOF
            AccTitle(i) = rst![AccTitle]
            DateAcc(i) = rst![DateAcc]
            AccType(i) = rst![AccType]
            AccSum(i) = rst![AccSum]
            i = i + 1
            rst.MoveNext
        Loop
            
        ' Accomplishment 1
        Me.txtAcc1.SetFocus
        Me.txtAcc1.Value = AccSum(1)
        Me.txtAccTitle1.Value = AccTitle(1)
        Me.txtType1.Value = AccType(1)
        ' Accomplishment 2
        Me.txtAcc2.Text = AccSum(2)
        Me.txtAccTitle2.Text = AccTitle(2)
        Me.txtType2.Text = AccType(2)
        ' Accomplishment 3
        Me.txtAcc3.Text = AccSum(3)
        Me.txtAccTitle3.Text = AccTitle(3)
        Me.txtType3.Text = AccType(3)
          
    End Sub

  2. #2
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164
    Of course, now that I post it I figure out a work around. Sorry if I wasted anyone's time.

    My solution was I moved the code setting the unbound text boxes from the Open event to the Load event. Between that and swapping out all the Text properties for Value properties I seem to have addressed my most pressing issue.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Thanks for posting your solution; it could help somebody later. As you found, the open event is too soon. I'll mark this thread solved for you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 06-14-2013, 01:50 PM
  2. Setting Report Height In Code
    By ccordner in forum Reports
    Replies: 1
    Last Post: 12-07-2012, 10:26 PM
  3. Replies: 10
    Last Post: 01-04-2012, 01:43 PM
  4. Setting Printer when Printing Report
    By russ0670 in forum Reports
    Replies: 3
    Last Post: 05-12-2010, 09:45 AM
  5. Setting a field in order for Report
    By cotri in forum Reports
    Replies: 2
    Last Post: 01-28-2010, 02:44 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
  •  
Other Forums: Microsoft Office Forums