Results 1 to 8 of 8
  1. #1
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112

    Calling up another form - Not Working

    Hi,


    I'm trying to call up a particular record in another form from the current form I'm on. I've tried different options for several days but it's still not working.

    The main form is frmPaymentSelectName. This form will list out the names of all students. When I click the "Pay" button on the side of the name, I want it to bring up the correct record in frmPaymentDetails.

    I'm encountering several problems currently.

    1) The "Pay" button will call ClickToPay_Click() when pressed. I have declared a temp dbgString, which I put on the watch window, to see what gets passed in.

    No matter which button I press (under the 3 different names), the name that's always sent in is "Rajah Gopal". If I press Chuck Smith's button, it will still send in "Rajah Gopal". Why is this happening?

    2) I'm trying to open the right record in frmPaymentDetails, by setting up the whereString. However, it is not working.

    I get a box prompting me to "Enter Parameter Value". Why does this happen?

    If I enter "Chuck" for example, I still get a blank frmPaymentDetails form.

    Ideal) What I want to happen is, when I press the button in frmPaymentSelectName for Chuck Smith for example, it brings me to Chuck Smith's record in frmPaymentDetails.

    Help anyone? Thanks.

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're code was not quite correct. The field names in the table have a space [First Name], but your code did not. I also included both the first and last names in the string. The corrected code is as follows

    Code:
        whereString = "[First Name] = " & "'" & Me.FirstName & "' AND [Last Name]='" & Me.LastName & "'"
        DoCmd.OpenForm "frmPaymentDetails", , , whereString, acFormEdit
    When you open the form, the first record will always have the focus, so to open the frmPaymentDetails form for another person, you must click in the name control for the person (this changes the focus) and then click their pay button.

  3. #3
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Quote Originally Posted by jzwp11 View Post
    You're code was not quite correct. The field names in the table have a space [First Name], but your code did not. I also included both the first and last names in the string. The corrected code is as follows

    Code:
        whereString = "[First Name] = " & "'" & Me.FirstName & "' AND [Last Name]='" & Me.LastName & "'"
        DoCmd.OpenForm "frmPaymentDetails", , , whereString, acFormEdit
    When you open the form, the first record will always have the focus, so to open the frmPaymentDetails form for another person, you must click in the name control for the person (this changes the focus) and then click their pay button.
    Thank you very much!

    There is something I don't understand. When I go to Design View in frmPaymentDetails, and I click on the PropertySheet for the [First Name] and [Last Name] fields, I go to the "All" tab and I see that the Name of the control does not have a space in between.

    The value of "control source" has a space (i.e. [First Name]) but the value of the "Name" of the control is actually [FirstName]), without the space.

    So I don't understand why the code with the space works?

    An additional quesiton: Is there a way for me to add code so that the user does not need to click on the name before clicking on the button?

    One simple idea is to just do away with the button and make the user double click the name.

    But if I wanted to keep the "button", is there a way for me to change the focus to the record clicked *after* he has clicked the button? I have no idea how to know which button he clicked from inside the code.

    Thanks!

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I don't usually use continuous forms that much, so I don't know of a way to change the focus other than clicking in one of the other controls. What I would do in this case is use a combo box that has the names and then when the name is selected in the combo box, open the other form. I have used your same query to populate the combo box in the attached database; please see form frmPaymentSelectName2.

  5. #5
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Thank you so much!

    Btw, do you have any idea why this is so?

    There is something I don't understand. When I go to Design View in frmPaymentDetails, and I click on the PropertySheet for the [First Name] and [Last Name] fields, I go to the "All" tab and I see that the Name of the control does not have a space in between.

    The value of "control source" has a space (i.e. [First Name]) but the value of the "Name" of the control is actually [FirstName]), without the space.

    So I don't understand why the code with the space works?
    Thanks!

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    The control source is the actual field name in your table or query. In both your tblMainStudentInfo and in the query that you use for the form, the first and last name fields have a space in them, so that is why the control source has a space in it. In queries, you can assign alias names to those field names, the alias name would then become the control source if you bound this query to a form

    SELECT tblMainStudentInfo.[First Name] as StudentFirstName etc.
    FROM tblMainStudentInfo

    If you use the form wizard or do a drag and drop of field names onto a form in design view, Access generally names the control the same as the field name of the table or query. Of course, you can change the control name, so why your controls are not the same as the field name suggests to me that they were changed at some point.

    Now as to the code statement below, the items shown in red are the FIELD names of the table or query while the items shown in blue are the FORM CONTROL NAMES that are supplying the data that will be used for the criteria based on the FIELD names indicated.

    whereString = "[First Name] = " & "'" & Me.FirstName & "' AND [Last Name]='" & Me.LastName & "'"

  7. #7
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Quote Originally Posted by jzwp11 View Post
    The control source is the actual field name in your table or query. In both your tblMainStudentInfo and in the query that you use for the form, the first and last name fields have a space in them, so that is why the control source has a space in it. In queries, you can assign alias names to those field names, the alias name would then become the control source if you bound this query to a form

    SELECT tblMainStudentInfo.[First Name] as StudentFirstName etc.
    FROM tblMainStudentInfo

    If you use the form wizard or do a drag and drop of field names onto a form in design view, Access generally names the control the same as the field name of the table or query. Of course, you can change the control name, so why your controls are not the same as the field name suggests to me that they were changed at some point.

    Now as to the code statement below, the items shown in red are the FIELD names of the table or query while the items shown in blue are the FORM CONTROL NAMES that are supplying the data that will be used for the criteria based on the FIELD names indicated.

    whereString = "[First Name] = " & "'" & Me.FirstName & "' AND [Last Name]='" & Me.LastName & "'"
    Thank you very much!

  8. #8
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome. Good luck with your project.

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

Similar Threads

  1. Calling fields into VBA Private Sub
    By fullshape in forum Programming
    Replies: 3
    Last Post: 02-18-2011, 09:22 AM
  2. Calling A Module Function To Open A Form
    By orcinus in forum Modules
    Replies: 3
    Last Post: 09-29-2010, 04:43 PM
  3. calling function
    By ManvinderKaur in forum Programming
    Replies: 3
    Last Post: 07-22-2010, 10:53 PM
  4. Replies: 4
    Last Post: 03-31-2010, 03:41 PM
  5. Calling a function and returning a value
    By 3dmgirl in forum Programming
    Replies: 0
    Last Post: 04-23-2007, 02:20 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