Results 1 to 13 of 13
  1. #1
    PhilTFC is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2012
    Posts
    14

    Control set to visible depending on text value of another control

    Hi i am sure this is a easy question for you guys

    I need a [Location] control on a form when = "First*" set [Invoiced] on the sameform to visible

    this is the code i am trying

    Private Sub Location_BeforeUpdate(Cancel As Integer)
    If Me.Location.Value = "First*" or "Arriva*" Then
    Me.Invoiced.Visible = True


    Else: Me.Invoiced.Visible = False
    End If
    End Sub

    any help will be greatly appreciated

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Er - what's the question?

  3. #3
    PhilTFC is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2012
    Posts
    14
    Hi Rod

    Thank you for your reply

    i need the [Invoiced] control on frmRecords to be visible when the [Location] on the frmRecords control contains the text "First*" or "Arriva*"
    and not visible when the [Location] control contains other text.

  4. #4
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Sorry, this sometimes still catches me out too.

    If Me.Location.Value = "First*" or "Arriva*" Then
    should be If Me.Location.Value = "First*" or Me.Location.Value = "Arriva*" Then

    Also Else: is a little unusual but should be OK. More normal to see the Else by its own on a separate line.

    All should now work.

  5. #5
    PhilTFC is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2012
    Posts
    14
    Have i got the code on the correct procedure setting (BeforeUpdate)? because the [Invoiced] control text box is not visible at all now


    Private Sub Location_BeforeUpdate(Cancel As Integer)
    If Me.Location.Value = "First*" Or Me.Location.Value = "Arriva*" Then
    Me.Invoiced.Visible = True
    Else: Me.Invoiced.Visible = False
    End If
    End Sub

  6. #6
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Code:
    Private Sub Location_BeforeUpdate(Cancel As Integer)
        If Me.Location.Value = "First*" Or Me.Location.Value = "Arriva*" Then
            Me.Invoiced.Visible = True
        Else
            Me.Invoiced.Visible = False
        End If
    End Sub
    In this case the before update event or the after update event may be used. After update may be marginally preferrable if you need to set the focus away from the [Invoiced] control.

    ... the [Invoiced] control text box is not visible at all now
    There's nothing wrong with the code. Do you mean that the control is hidden upon form load? Either go to the form design window and set the [Invoiced] control's visible property to Yes or include a small procedure in the form's on load and on current events.

  7. #7
    PhilTFC is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2012
    Posts
    14
    I have tried your suggestions and the [Invoiced] control is still not showing at all.
    There is only one form which is visible all the time. Could it have something to do with the widcard "*" ("First*" Or Me.Location.Value = "Arriva*") because there is more text so find in the [Location] control text box?

  8. #8
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Argh!

    Code:
    Private Sub Location_BeforeUpdate(Cancel As Integer)
        If Me.Location.Value Like "First*" Or Me.Location.Value Like "Arriva*" Then
            Me.Invoiced.Visible = True
        Else
            Me.Invoiced.Visible = False
        End If
    End Sub
    Use the 'Like' operator! I thought you were testing for an asterisk.

  9. #9
    PhilTFC is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2012
    Posts
    14
    i thought that might do it but its still not showing the [Invoiced] control
    i just tried it with the text "First" only and it worked but i need it to work on "First South Yorkshire" or "First West Yorkshire"for example
    so it could be the way i am using the wildcard... almost there i can feel it

  10. #10
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Can you post your db? Meanwhile I shall try to replicate your problem.

    P.S. Later - works like a charm for me! Something else is going on - usually something quite obvious that will lead to that 'Duh!' moment. We'll have to debug your db.

  11. #11
    PhilTFC is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2012
    Posts
    14
    i keep getting a message saying the db is to big

  12. #12
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Is that a forum message? You may have to Zip it.

  13. #13
    PhilTFC is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2012
    Posts
    14
    Hi Rod

    The problem has now been solved, thank you so much for your time.
    i attached this code on the OnCurrent event and it works a treat
    Private Sub Form_Current()
    If Left(Me.Location.Value, 5) = "First" Or _
    Left(Me.Location.Value, 6) = "Arriva" Then
    Me.txtInvoiced.Visible = True
    Else
    Me.txtInvoiced.Visible = False

    End If
    End Sub

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

Similar Threads

  1. Replies: 6
    Last Post: 09-14-2012, 01:44 PM
  2. Replies: 1
    Last Post: 06-15-2012, 05:08 AM
  3. Replies: 13
    Last Post: 05-14-2012, 03:41 AM
  4. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  5. Text control to act like combo control
    By chris.williams in forum Programming
    Replies: 2
    Last Post: 11-11-2011, 10:12 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