Results 1 to 2 of 2
  1. #1
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82

    Show certain fields based on the value of a field on the same form

    Hi



    I have a field on my form called "QueryType" (it is a query management DB). When a user wants to log a query they must select a query type. It is a drop down box currently with 14 options. It gets its possible values from a lookup of another table.

    Certain Queries require additional fields. When the query type is changed to lets say "DDIC", I want two additional fields to become visible (they are currently invisible) "OrigName" and "OrigNum".


    I have tried the following code as onChange event of the field "QueryType" but to no avail

    DDIC Has an ID of "3"


    Code:
    Private Sub QueryType_Change()
        Dim QueryID As Integer
        
        QueryID = DLookup("ID", "tblQueryTypes", "Type='" & Me.QueryType.Value & "'")
        If (QueryID) = 3 Then
            Me.lblOriginatorName.Visible = True
        End If
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You're almost there,
    first, you declared QueryID as INTEGER, yet you Dlookup the "Type='" & Me.QueryType.Value & "'" AS STRING.
    Is the ID numeric or string?

    I dont see the need to do the Dlookup if the user has already picked it in the combo box.
    IF the table tblQueryTypes uses unique text codes (DDIC), then it doesnt need numeric keys. But if youve already started with numerics, keep it.

    Does the combo box QUERY, have ID# keys AND text (DDIC) fields showing? It could be the combo box is set to the wrong BOUND COLUMN.

    I would use:
    Code:
    Private Sub QueryType_Change()                              'combo boxs should be named with cbo prefix  ...cboQueryType
             lblOriginatorName.Visible = (QueryType) = 3        '  (with correct bound column)
             lblOrigNum.Visible = (QueryType) = 3
    end sub

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

Similar Threads

  1. Replies: 5
    Last Post: 03-03-2015, 09:08 PM
  2. Replies: 8
    Last Post: 10-03-2014, 01:34 PM
  3. Show/Hide Fields based on criteria.
    By jtm013 in forum Queries
    Replies: 6
    Last Post: 08-14-2014, 08:05 AM
  4. Replies: 3
    Last Post: 07-20-2014, 08:56 PM
  5. Autofill form fields based on another field
    By ljs1277 in forum Access
    Replies: 3
    Last Post: 02-16-2010, 02:51 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