Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2011
    Posts
    5

    control button issue

    Please forgive me for my Noobieness - I am trying to create a control button that will open a form based on particular field on my main form. I tried to use the button wizard but that didn't work so I copied the event procedure code from another control button and edited it to point to the correct form to open when clicked. Here is the code:

    __________________________________________
    Private Sub Fred_Click()
    On Error GoTo Err_Fred_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Basler BE125 SETTINGS"

    stLinkCriteria = "RELAY![RELAY #]=" & Me![RELAY #]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Exit_Fred_Click:
    Exit Sub
    Err_Fred_Click:
    MsgBox Err.Description
    Resume Exit_Fred_Click

    End Sub
    ___________________________________________

    Fred was the unique identifier I chose so it would stand out better when I was looking at all the code. The way the control button is suppossed to work, you select a particular Relay # on the Relay Tab Sheet and then click on the BE-125 button to open to a single filtered record on the Basler BE125 Setting form. Instead, I get a pop up box asking for the Relay# and once I enter it, I still get all 84 items in my table. Any ideas? Thanks!!!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Instead of this:
    Code:
     
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Try something like this:
    Code:
     
    DoCmd.OpenForm stDocName, , , "Relay # = '" & Me.[Relay #] & "'"
    Using spaces and # signs in field names is dodgy. Better to avoid them. It just simplifies things.

    Let me know if this helps.

  3. #3
    Join Date
    Sep 2011
    Posts
    5
    Syntax error in date in query expression 'Relay # = '11885". is the error message I receive now. The 11885 is the actual field data from the Relay Tab Sheet.

    Should I have removed or altered the stLink Criteria line?

    As for the spaces and # symbol, this DB was created by another user and dumped on me to use/maintain. I don't know if I'm quite up to the challange of correcting mistakes like that.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Yeah . . . that's why I don't like spaces and reserved words [#] in field names.

    As a test, try changing the field names on both your Forms to RelayNum and do this:



    Code:
     
    DoCmd.OpenForm stDocName, , , "RelayNum = '" & Me.RelayNum & "'"
    and see if that works.

  5. #5
    Join Date
    Sep 2011
    Posts
    5
    I'm not sure I can do that - my data tables are located on a SQL Server and I don't have access to alter the field names. I'll have to put through a request in order to do that and I'm concerned other users will have issues once this change happens.

    Did I need to alter the stLinkCriteria line at all?

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    The correct syntax (with the spaces since you have them) is:
    Code:
    stLinkCriteria = "[RELAY #]=" & Me![RELAY #]
    But if Relay # is text then it would be
    Code:
    stLinkCriteria = "[RELAY #]=" & Chr(34) & Me![RELAY #] & Chr(34)

  7. #7
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You don't have to alter the field names in your Tables.

    Just change the Names of the Text Boxes on your Forms. They will still point to the same Table field names.

  8. #8
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272

    Thumbs up Good suggestion

    Quote Originally Posted by Robeen View Post
    You don't have to alter the field names in your Tables.

    Just change the Names of the Text Boxes on your Forms. They will still point to the same Table field names.
    Good suggestion.

  9. #9
    Join Date
    Sep 2011
    Posts
    5
    OK - that got rid of the date error issue but I'm right back where I started from. I get a popup called RelayNUM, when I enter the relay number and click OK, I get the correct form to open but all the records in the table. Here is my code now:

    Private Sub Fred_Click()
    On Error GoTo Err_Fred_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Basler BE125 SETTINGS"

    stLinkCriteria = "[RELAYNUM]=" & Me![RelayNUM]
    DoCmd.OpenForm stDocName, , , "RelayNUM = '" & Me.[RelayNUM] & "'"
    Exit_Fred_Click:
    Exit Sub
    Err_Fred_Click:
    MsgBox Err.Description
    Resume Exit_Fred_Click

    End Sub

  10. #10
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You aren't using the correct code again, you need:
    Code:
    stLinkCriteria = "[RELAY #]=" & Me![RelayNUM]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    The FIRST part you have to use the FIELD name (red) and then the Control name in the second part (blue) and then you have to use the variable which you just created (green), or else it shouldn't be there and the value should be just in the WhereCondition of the DoCmd.OpenForm code.

  11. #11
    Join Date
    Sep 2011
    Posts
    5
    GOT IT - IT WORKS!!!!!!!!!!!!!!!!!!!!!

    Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!

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

Similar Threads

  1. How to control a button when it has focus
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 07-28-2011, 03:18 PM
  2. Query Quality Control Issue
    By ittech70 in forum Queries
    Replies: 1
    Last Post: 01-12-2011, 10:52 AM
  3. a-z sort for control button
    By darklite in forum Access
    Replies: 7
    Last Post: 05-28-2010, 04:49 AM
  4. Command button issue
    By sloppysly in forum Forms
    Replies: 8
    Last Post: 06-15-2009, 12:07 PM
  5. Replies: 0
    Last Post: 01-22-2009, 03:38 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