Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Location
    UK
    Posts
    85

    Question Unanswered: Option group and parameter fiels

    Dear All

    I have got following objects on a form
    An option group with 2 options (Option 1. Part No, Option 2. Ref No)
    A command button to open a report based on a query

    What I want?

    I chose an option, say option for Part No. Now when I click on command button to open the report based on a query, I want Part No field to be set as a parameter for that query. So that after clicking on command button it would prompt for the Part no. Similarly if I chose option 2 then on clicking the command button it prompts for Ref No.

    I hope I am able to explain my problem. Looking forward to reply.

  2. #2
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Re: Option group and parameter fiels

    Originally posted by dbase
    Dear All

    I have got following objects on a form
    An option group with 2 options (Option 1. Part No, Option 2. Ref No)
    A command button to open a report based on a query

    What I want?

    I chose an option, say option for Part No. Now when I click on command button to open the report based on a query, I want Part No field to be set as a parameter for that query. So that after clicking on command button it would prompt for the Part no. Similarly if I chose option 2 then on clicking the command button it prompts for Ref No.

    I hope I am able to explain my problem. Looking forward to reply.
    What about this :

    Code:
    Private Sub grpTest_Change()
         Dim strSQL as String
         Dim strParameter as String
    
        if grpTest.Value = 1 Then
           strParameter = InputBox("Give Part No")
        else
           strParameter = InputBox("Give Ref No")
        end if
    
        strSQL = "SELECT .... FROM ...... WHERE ..... = " & strParameter
    End Sub

  3. #3
    Join Date
    Mar 2003
    Location
    UK
    Posts
    85
    Artemide

    Thank you very much for your reply.

    Just a little problem as I am in a very early stages of learning of VB codes. Can you please explain it in a bit more detail where would I use this code, in OnClick event of command button or in some event of option group? And also in strSQL statement

    strSQL = "SELECT .... FROM ...... WHERE ..... = " & strParameter

    does the dots mean anything or there is something I need to insert in these spaces. (I know I soud stupid but thus is how I would learn)

    Thanks again

  4. #4
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243
    Originally posted by dbase
    Artemide

    Thank you very much for your reply.

    Just a little problem as I am in a very early stages of learning of VB codes. Can you please explain it in a bit more detail where would I use this code, in OnClick event of command button or in some event of option group? And also in strSQL statement

    strSQL = "SELECT .... FROM ...... WHERE ..... = " & strParameter

    does the dots mean anything or there is something I need to insert in these spaces. (I know I soud stupid but thus is how I would learn)

    Thanks again
    When you placed an optiongroup on your form you will notice all the optionbuttons with their corresponding labels.
    Arround all this there is a frame which is the optiongroup.
    Doubleclicking on it will ppopup a properties-window.
    On the 'Events'-tab you'll find an 'After Update'-event.
    Everytime you swith between optionbuttons these event is triggered.
    I attached a small example.


    About the SQL-string :
    After 'SELECT' you can write down all the fields you want displayed in your result. Fields are seperated by a comma.
    After 'FROM' you write down the name(s) of the table(s) where access should search for the desired fields.
    If you are not familiar with SQL it's a bit difficult using the different types of JOINS (= combining tables)
    After 'WHERE' you can write down some conditions to filter your result.

    Building a query in access is just a grahical way to generate SQL-code.
    When you create a query in access you can go to SQL-view.
    There you can find the exact SQL-string.
    Maybe this is a good start to learn more about SQL.

    Hope this helps.
    If not, let us know.
    Attached Files Attached Files

  5. #5
    Join Date
    Mar 2003
    Location
    UK
    Posts
    85

    Smile

    Artemide

    Thank you very much for your reply and your guidance. It has really helped me.

    I hope this would work and if it does't, I would come back to you.

    Thanks again for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •