Results 1 to 6 of 6
  1. #1
    JohnsonG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    4

    Compare Multiple Fields from Current Record and Populate Text Box

    My first time creating an Access report, so I apologize if this is a simple task. I have experience with writing VBA for Excel, but I'm not familiar with the means or methods here.
    Click image for larger version. 

Name:	Access Screen Shot.jpg 
Views:	9 
Size:	207.9 KB 
ID:	21025


    Above is a screenshot of my report. Most text boxes have the Control Source as a field from a table (TAG_NO, EDESC, etc..). These work as expected when I view a print preview of the report. However, the Services Required text box needs to compare multiple fields from the current record and then populate the text box. I was thinking maybe I need to create a BeforeUpdate event for the text box or something along those lines and compare the fields for the current record. However, I'm clueless how to code this. Any help would be greatly appreciated. Let me know if you need anything else.
    Last edited by JohnsonG; 06-16-2015 at 07:58 AM. Reason: Tried to Reattach Screenshot Image

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    the screenshot is unavailable, but if you need to populate other textboxs, then your query needs to link to the tables that HAVE the data, then bring down the needed fields into the query.

  3. #3
    JohnsonG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    4
    Ranman thanks for your response! I tried to reattach the image to my original post, because it will make more sense. I did successfully bring in the table with the data I need, and I linked many of the fields to existing text boxes. There's just the one text box I need to compare multiple fields that's highlighted in the screenshot.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Not sure what you mean by 'compare'. you dont comare in a report.
    do you mean link the field to a table and get the result?

  5. #5
    JohnsonG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    4
    I've linked many fields to a table and it works as expected. However, one of the text boxes I report needs to have logic based on 5 different fields from the linked table. Is there a way I can create vb code to do this?

  6. #6
    JohnsonG is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    4
    I was able to figure out a way to accomplish what I needed to get done. I set the Control Source equal to a function I created. I then placed 5 invisible text boxes and linked them to the fields I needed to compare. Without placing these invisible text boxes linked to the fields in my report, the function wouldn't work.

    Click image for larger version. 

Name:	Control Source.png 
Views:	5 
Size:	29.1 KB 
ID:	21053

    Here's the code of the function:

    Public Function GetServicesReqd() As String
    Dim servreqd As String

    servreqd = ""

    If Me.NO_SERVICES_REQD = "Yes" Then
    servreqd = ""
    GoTo leavefunct
    End If

    If Me.BASE_REQD = "Yes" Then
    servreqd = servreqd & "B"
    End If

    If Me.CONTROLS_REQD = "Yes" Then
    servreqd = servreqd & "C"
    End If

    If Me.ELECTRICAL_REQD = "Yes" Then
    servreqd = servreqd & "E"
    End If

    If Me.FREEZE_PROT_REQD = "Yes" Then
    servreqd = servreqd & "F"
    End If


    leavefunct:
    GetServicesReqd = servreqd

    End Function

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

Similar Threads

  1. Populate form with current record
    By drew17 in forum Forms
    Replies: 1
    Last Post: 06-30-2014, 11:23 AM
  2. BeforeUpdate compare two fields on same record
    By blacknblue in forum Programming
    Replies: 2
    Last Post: 10-23-2012, 06:42 PM
  3. Replies: 4
    Last Post: 01-30-2012, 08:32 AM
  4. Help with if statement to compare multiple fields
    By usmcgrunt in forum Programming
    Replies: 2
    Last Post: 12-01-2010, 06:43 PM
  5. Replies: 1
    Last Post: 02-03-2010, 09:17 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