Results 1 to 11 of 11
  1. #1
    louisrockzzz is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2016
    Posts
    4

    Problem With Form To Form and Buttons


    Hi. I am creating a database to log donations and the donors that gave the donation. I have a table for Donor_Information, which stores the donor number, name, company, address, etc., Donations_Given, which stores the number of the donor who gave the gift as well as other important gift information, as well as many other tables. I have created a split form for a donor search form. What I want to be able to do is use the search results, select one of them, which populates the Donor_Num text box automatically, put a button to add a new donation which would open the add a new donation form, take that donor that is selected and whose Donor_Num is auto populated in the box, and have their number be put into the donor_num field in the donation form so they do not have to enter one. I have tried several different methods and have done much googling but haven't been able to make it work. I'm sure its and easy fix and I am just missing it because I am googling the wrong thing. Any help would be appreciated.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't have A2016 and I don't use "split forms", but have you heard about the "OpenArgs" parameter of "Docmd.OpenForm" method?
    Maybe it will help.

    See http://www.datawright.com.au/access_..._arguments.htm
    Example for using "OpenArgs" is at the bottom.... but read the whole thing...

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    To add to Steve's suggestion, here's another example: http://www.baldyweb.com/OpenArgs.htm

  4. #4
    louisrockzzz is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2016
    Posts
    4
    I am getting subscript out of range errors. Heres some of my coding. Any help is appreciated.

    This is for the button on the first form.
    Private Sub Command116_Click()
    DoCmd.OpenForm "Add A New gift", acNormal, , , acFormAdd, , "DonorNum" & Me.DonorNum
    End Sub

    Private Sub Form_Load()
    'Use this version if the ID is a number
    Dim strOpenArgs() As String

    This is for the form I want to open when I click the button.
    If Not IsNull(Me.OpenArgs) Then
    strOpenArgs = Split(Me.OpenArgs, ";")
    Me.DonNumBox = strOpenArgs(0)

    Else


    End If
    End Sub


    I am not sure what to put in the else to handle the the open args is the donor num box is blank. Thanks

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Change this line:
    DoCmd.OpenForm "Add A New gift", acNormal, , , acFormAdd, , "DonorNum" & Me.DonorNum
    ...to...
    DoCmd.OpenForm "Add A New gift", acNormal, , , acFormAdd, , Me.DonorNum

  6. #6
    louisrockzzz is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2016
    Posts
    4
    Yes I realized after I posted that that that was wrong. The issue I'm having now is when the field is empty I get an error as suchClick image for larger version. 

Name:	a.JPG 
Views:	13 
Size:	81.8 KB 
ID:	25790Click image for larger version. 

Name:	b.JPG 
Views:	13 
Size:	47.0 KB 
ID:	25791 I would like it to be able to either not load the form, or load a blank version of form. Also, I would like to set the focus to a different box when the from is opened.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    ALL values passed in the OpenArgs argument are STRINGS always. You will need to coerce the value into the DonNumBox control. What is the Data Type of the field to which the DonNumBox is bound? If it is an Integer then CInt(Me.DonNumBox = strOpenArgs(0)) should do it. As for the focus, the tab order can set that or you can just do a Me.YourControlName.SetFocus in the Load event.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @RG

    Umm, shouldn't that be
    Me.DonNumBox = CInt(strOpenArgs(0))

  9. #9
    louisrockzzz is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Sep 2016
    Posts
    4
    The Donor Num is all just numbers. The code works fine once I select a donor from the donor search form, but if I do not select one I encounter that error as stated above. So I need to know what I can do to either have it open a blank form or make it set that a donor must be selected before opening the form. Let me know if any further pictures or code will help answer.

    Edit
    I would prefer it just say that you must select a donor from the search box since I have the donor num on the gift form set to locked.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Quote Originally Posted by ssanfu View Post
    @RG

    Umm, shouldn't that be
    Me.DonNumBox = CInt(strOpenArgs(0))
    D'uh...absolutely! Thanks Steve.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Code:
    If Len(Me.DonorNum & "") <> 0 Then
       DoCmd.OpenForm "Add A New gift", acNormal, , , acFormAdd, , Me.DonorNum
    Else
       Msgbox( "Please select a donor...etc"
    End If

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

Similar Threads

  1. Form Buttons
    By dave_282 in forum Access
    Replies: 2
    Last Post: 02-16-2016, 05:53 PM
  2. Form Buttons
    By DCV0204 in forum Forms
    Replies: 9
    Last Post: 11-30-2011, 02:34 PM
  3. Form Buttons
    By DCV0204 in forum Forms
    Replies: 2
    Last Post: 11-29-2011, 03:21 PM
  4. Replies: 3
    Last Post: 10-29-2011, 04:25 AM
  5. Form and Buttons
    By rmohebian in forum Forms
    Replies: 1
    Last Post: 02-14-2011, 09:57 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