Results 1 to 10 of 10
  1. #1
    Not2gassy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    6

    Pass input value to AddForm from notinlist on a MainFom


    I see similar posts, but mine is so simple that I don't see it. I have a main input form with a combo box where I want to add new items for notinlist instances. Everything seems to work ok except I cannot get the value input on the main form to pass thru to populate the AddForm. The relevant code for the notinlist property on the main form is:
    Code:
     Private Sub City_NotInList(NewData As String, Response As Integer)      Dim strType As String, strWhere As String        'User has typed in a city name that does not exist        strType = NewData        'Set up the test predicate        strWhere = "[City] = """ & strType & """"        'Ask if they want to add this city        If MsgBox("City " & NewData & " is not found. " & "Do you want to add this City?", vbYesNo + vbQuestion + vbDefaultButton2, gstrAppTitle) = vbYes Then        'Yup, Open the product add form and pass it the new name        DoCmd.OpenForm "CityAdd", DataMode:=acFormAdd, WindowMode:=acDialog, OpenArgs:=Me.City = NewData        'Verify that City really was added        If IsNull(DLookup("CityID", "CityTable", strWhere)) Then        'Nope       MsgBox "You failed a City that matched what you entered." & "Please try again.", vbInformation, gstrAppTitle        'Tell Access to continue - we trapped the error        Response = acDataErrContinue        Else        'City added OK - tell Access that Field gets requeried        Response = acDataErrAdded        End If        Else        'Do not want to add - let Access display normal error        Response = acDataErrDisplay        End If  End Sub    On the Addform I have put the following code in the on Current property:  Private Sub Form_Current() If Me.NewRecord Then Me.City = Me.OpenArgs End Sub
    The problem seems to be in the DoCmd statement. I thought the OpenArgs portion would do it, but something is not right. Thanks.
    Last edited by Not2gassy; 06-24-2014 at 06:25 PM.

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    You need to re-post this and add Code Tags. Too hard to read.

  3. #3
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    OpenArgs:= City = NewData

    Is wrong, should be:

    OpenArgs:= NewData

    Then you can use Me.OpenArgs in your data entry forms code to retrieve the value. Best place for this is the open event.

  4. #4
    Not2gassy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    6
    Quote Originally Posted by burrina View Post
    You need to re-post this and add Code Tags. Too hard to read.
    Yeh, I noticed the formatting was messed up. What are code tags and how do I add them to get it to look right? Not2gassy

  5. #5
    Not2gassy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    6

    Still get an error message

    Thanks for the suggestions - Ok, I changed the the OpenArgs statement to OpenArgs:=NewData in the notinlist event on the Main form. It still doesn't like the Me.OpenArgs statement in the onOpen event of the CityAdd form. It says it is a property mismatch. The CityAdd form is opening in datamode add. Thanks for taking your time for this.

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    It's the Wrap Code button to your far right above. Highlight your code and press it ONCE.
    Thanks,

  7. #7
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Can you please repeat the code off the open event sub, as you have it now?

  8. #8
    Not2gassy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    6

    The Open event sub on the CityAdd form.

    Quote Originally Posted by hapm View Post
    Can you please repeat the code off the open event sub, as you have it now?
    Code:
     Private Sub Form_Open(Cancel As Integer)  Me.OpenArgs   End Sub 

  9. #9
    Not2gassy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    6
    Thanks. The problem was that I was blocking too much scripting - I tend to be a little paranoid.

  10. #10
    Not2gassy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    6

    Smile Problem Solved

    Thanks all. I figured it out with a little reference reading.

    The codes are:
    for the Main form -
    Code:
    Private Sub City_NotInList(NewData As String, Response As Integer)
        Dim strType As String, strWhere As String
          'User has typed in a city name that does not exist
          strType = NewData
          'Set up the test predicate
          strWhere = "[City] = """ & strType & """"
          'Ask if they want to add this city
          If MsgBox("City " & NewData & " is not found. " & "Do you want to add this City?", vbYesNo + vbQuestion + vbDefaultButton2, gstrAppTitle) = vbYes Then
          'Yup, Open the product add form and pass it the new name
          DoCmd.OpenForm "CityAdd", DataMode:=acFormAdd, WindowMode:=acDialog, OpenArgs:=NewData
          'DoCmd.OpenForm "formname", , , "EmployeeID=" & Me.EmployeeID
          'Verify that City really was added
          If IsNull(DLookup("CityID", "CityTable", strWhere)) Then
          'Nope
          MsgBox "You failed a City that matched what you entered." & "Please try again.", vbInformation, gstrAppTitle
          'Tell Access to continue - we trapped the error
          Response = acDataErrContinue
          Else
          'City added OK - tell Access that Field gets requeried
          Response = acDataErrAdded
          End If
          Else
          'Do not want to add - let Access display normal error
          Response = acDataErrDisplay
          End If
    End Sub
    and for the CityAdd form it is -

    Code:
    Private Sub Form_Load()
    
        Me.City = Me.OpenArgs
        
        
    End Sub

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

Similar Threads

  1. combo box w/ NotInList
    By benjammin in forum Forms
    Replies: 8
    Last Post: 05-27-2011, 10:10 AM
  2. NotInList event
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 04-13-2011, 09:10 AM
  3. NotInList event issue
    By elinde in forum Forms
    Replies: 1
    Last Post: 04-01-2011, 08:43 PM
  4. Cancelling the NotInList event
    By Remster in forum Programming
    Replies: 12
    Last Post: 11-21-2010, 10:12 AM
  5. NotInList with Many to Many
    By SAC in forum Programming
    Replies: 17
    Last Post: 11-21-2010, 06:42 AM

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