Results 1 to 8 of 8
  1. #1
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63

    Help with opening form to specific record

    Hello all, I'm kinda stuck here trying to figure something out. I have this function:


    Code:
    Function OpenFormWithInput()
       Dim Msg As String
       Dim Title As String
       Dim Defvalue As String
       Dim Answer As String
      Msg = "Enter Employee Name (Last Name and First Name: Smith,John)No space after the ,."
       Title = "OPEN SAFETY CHAMPION FORM"
       Defvalue = "JOHN,SMITH"
       Answer = InputBox(Msg, Title, Defvalue)
       If Answer <> "" Then
          DoCmd.OpenForm "frm_Safety_Champion_Updater", , , "[employee_name]='" & Answer & "' "
       Else
       DoCmd.Close
          DoCmd.OpenForm "frm_EHS_Safety_Section", acNormal
          
       End If
    End Function
    sample.zipWhen I call the function, the input box pops up for the user to enter the name to pull the records that have that name on it. If they put the wrong name the function will open a new form but I don’t want them entering new information on that form so on the current event of the form I entered the code that if is a new record a msg box pops and tells them that they entered the wrong name to click yes to try again and no to exit if you click yes it calls the function again and if the name is entered wrong again, even thou the blank form gives them the msg that the name is wrong or do not exist the second time around the function will open the form regardless.
    I included a sample.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Do you have a table of employee names? I ask because the way you have it set up, you can/will get spelling errors/typos etc and you have no code to intercept or check spelling.

  3. #3
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    Quote Originally Posted by orange View Post
    Do you have a table of employee names? I ask because the way you have it set up, you can/will get spelling errors/typos etc and you have no code to intercept or check spelling.
    yes i do have a table with names, I just changed them due to privacy i guess.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    It 's probably just me, but I've read your post, gone away, come back and reread it, and I can't, for the life of me, understand exactly what you're saying! But if you're trying to open the frm_Safety_Champion_Updater Form, if the employee name entered is valid, but do something else if it’s not, what I do, for this kind of thing is to check to see if the name is valid, using Dcount(), before executing the command to open the Form:
    Code:
    If DCount("*", "tbLEmployees", "[employee_name]='" & Answer & "'") > 0 Then
      DoCmd.OpenForm "frm_Safety_Champion_Updater", , , "[employee_name]='" & Answer & "' "
    Else  'If the name is NOT VALID
     'Code to do something else goes here
    End If


    If I could understand your complete intent , here, I could probably incorporate it into your code better.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    Check the sample I uploaded. open the Form1 and click ok, you will get an error and you get the option to go back but if you make the same exact mistake the form will open the second time around . may I can't explained well, please check the sample
    Attached Files Attached Files

  6. #6
    PATRICK is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    32

    New Sample

    Manic I was reviewing your code and did some modifications, in attached are you sample file modified. try it and see if this is what you want.
    Patrick.
    Attached Files Attached Files

  7. #7
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    Quote Originally Posted by PATRICK View Post
    Manic I was reviewing your code and did some modifications, in attached are you sample file modified. try it and see if this is what you want.
    Patrick.

    thanks Patrick, that's what I need.

  8. #8
    PATRICK is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2011
    Posts
    32
    good... glad that worked for you. Good luck with your software.

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

Similar Threads

  1. Opening Form from a Different Form to Specific Data
    By audreyestelle in forum Forms
    Replies: 3
    Last Post: 07-26-2012, 01:41 PM
  2. Replies: 15
    Last Post: 04-17-2012, 01:42 PM
  3. opening up form on specific part of the page
    By gbmarlysis in forum Forms
    Replies: 1
    Last Post: 02-29-2012, 05:06 PM
  4. Replies: 9
    Last Post: 09-16-2011, 03:52 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