Results 1 to 10 of 10
  1. #1
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17

    Opening Form to a Specific Record

    Hey Guys,

    To simplify, I'm currently writing a module that (at one point) will allow me to open the "90-Hr Waiting PU Form" to the same record that was on the "90-Hr Sheet Request Form". Here is the full code for the module below:



    Code:
     DoCmd.OpenQuery "Append from Request to PU (Step 1 to 2)", acViewNormal, acEdit
     DoCmd.OpenForm "90-Hr Waiting PU Form", acNormal, "", "[90-Hr Sheet Request Form].StudentIDTextBox" = "[90-Hr Waiting PU Form].StudentIDTextBox", acEdit, acNormal
     DoCmd.OpenQuery "Delete Query (from Request)", acViewNormal, acEdit
     DoCmd.Close acForm, "90-Hr Sheet Request Form"
    The command where I open the form (the one in bold) is the one I'm focusing on. I need to specify the "Where Condition": to open the PU Form to the record that was just appended in the previous line. I'm thinking of making it a filter, so that it opens to where the StudentIDTextBox in form 2 is equal to StudentIDTextBox in form 1. How would you write or change this code to get it to work?

    Thank you for your time.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Concatenate variables, reference to control on form is a variable.

    DoCmd.OpenForm "90-Hr Waiting PU Form", acNormal, , "StudentID = '" & Me.StudentIDTextBox & "'"

    What is the name of student ID field? Is it a number or text field? If it is number then remove the apostrophe delimiters.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17
    The name of the field is simply "Student ID" (a number field), and on the form it is brought up in the "StudentIDTextBox". I have to check it tomorrow when I'm back at work, but what would it be without the delimiters? Thank you again.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Yes, without delimiters. If the field name has space must enclose in []:

    "[Student ID]=" & Me.StudentIDTextBox

    Advise not to use spaces or special characters/punctuation (underscore is exception) in names.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17
    Thank you again for your response, but it says it's an "Invalid use of the Me keyword", any ideas? But to play with it, I tried changing to:

    "[Student ID]=" & [90-Hr Sheet Request].StudentIDTextBox

    but it gave me "Compile Error: External Name Not Defined". Here is my full code as it is now:

    [CODE]
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Append from Request to PU (Step 1 to 2)", acViewNormal, acEdit
    DoCmd.OpenForm "90-Hr Waiting PU Form", acNormal, "", "[Student ID]=" & [90-Hr Sheet Request Form].StudentIDTextBox, acEdit, acNormal
    DoCmd.OpenQuery "Delete Query (from Request)", acViewNormal, acEdit
    DoCmd.Close acForm, "90-Hr Sheet Request Form"
    [CODE/]

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Note that ending code tag has / at beginning, not end.

    Where is the code placed and where is the textbox? Try:

    "[Student ID]=" & Forms.[90-Hr Sheet Request].StudentIDTextBox

    Is StudentID a number field type?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17
    Yes, Student ID is a number field type. And just tried that, and (on Access itself, not on the VBA module for once) I got the message "Object doesn't support this property or method". We're getting close, but I'd appreciate a little more help if thats ok haha (thank you June7).

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Then answer the other question posed in previous post. I don't know your database, although the form names sound vaguely familiar.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17
    I decided to attach my Database as it is so that you can take a look at it (its only 1.2mb). Hopefully this will help!90 Hr DB.zip

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Part of issues with this database is all the 'moving' of data between tables. Never seen one with this much moving. I wouldn't do this. I would instead do one of the following:

    1. Change a status field in table

    2. Have a child table to document each change in status, like a history, each change would be a record with a date and action code and studentID

    This is definitely not a truly relational database. If it were, this 'moving' would not be necessary.

    Having said all that, issue with the code appears to be that the form name has the word 'Form' included as shown in your post but the actual code does not.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Help with opening form to specific record
    By manic in forum Programming
    Replies: 7
    Last Post: 09-18-2012, 08:44 PM
  2. Opening Form from a Different Form to Specific Data
    By audreyestelle in forum Forms
    Replies: 3
    Last Post: 07-26-2012, 01:41 PM
  3. Replies: 15
    Last Post: 04-17-2012, 01:42 PM
  4. opening up form on specific part of the page
    By gbmarlysis in forum Forms
    Replies: 1
    Last Post: 02-29-2012, 05:06 PM
  5. Replies: 1
    Last Post: 11-09-2010, 03:02 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