Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2004
    Posts
    32

    Unanswered: Detecting which option button selected

    Hi:

    I have a search form where one of two methods may be employed to search for records on a geographic basis - townships and NTS (a geographical term, don't worry about understanding it). The user can use only one of the two methods to search for records and I have two options buttons, Townships/NTS, that determine which method is being used for the search. In both cases, the searches are via a list - if you select Townships, the list of townships appears (using the Visible=true property) and the same is true for NTS. However, in the VB code, I need to detect which method was chosen, NTS or Townships and I thought something like:

    <code>
    if Forms!Search_Pubs!btnTownships.Selected = True then ...
    </code>

    would work but it doesn't. How do I determine if a particular option button has been selected?

    TIA,
    Jules

  2. #2
    Join Date
    Feb 2004
    Posts
    32

    Re: Detecting which option button selected

    Sorry, forgot to add:

    Access 97

  3. #3
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Detecting which option button selected

    Originally posted by jrickards
    Hi:

    I have a search form where one of two methods may be employed to search for records on a geographic basis - townships and NTS (a geographical term, don't worry about understanding it). The user can use only one of the two methods to search for records and I have two options buttons, Townships/NTS, that determine which method is being used for the search. In both cases, the searches are via a list - if you select Townships, the list of townships appears (using the Visible=true property) and the same is true for NTS. However, in the VB code, I need to detect which method was chosen, NTS or Townships and I thought something like:

    <code>
    if Forms!Search_Pubs!btnTownships.Selected = True then ...
    </code>

    would work but it doesn't. How do I determine if a particular option button has been selected?

    TIA,
    Jules
    Check for the .value property. Actually you can use the name of the option by itself, since the value property is the default property.
    Have your code look to see if it is -1 or 0 (Selected/Not Selected) and perform actions accordingly.

    Gregg

  4. #4
    Join Date
    Feb 2004
    Posts
    32
    I tried

    test = Forms!Search_Pubs!btnTownships.Value

    but the Debug code is telling me that the expression has no value even though I selected the Townships button in the form.

  5. #5
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445
    Originally posted by jrickards
    I tried

    test = Forms!Search_Pubs!btnTownships.Value

    but the Debug code is telling me that the expression has no value even though I selected the Townships button in the form.
    Is the form that you are in the one that is running the code?

    If it is then it will be easier and less prone to syntax errors if you use Me to refer to your current form. Me.btnTownships.

    If you still have problems, I guess I'm not clear on what or where you are doing what you are doing.

    If Me.btnTownships = -1 Then
    Do something
    Else
    Do something Else
    End If

  6. #6
    Join Date
    Feb 2004
    Posts
    32
    No, Me doesn't work because I am running an external module so I have to reference the Form explicitly.

    Attached is a screenshot of the form in design view.

    Below is the code I am using in the module

    Code:
    If IsNull(Forms!Search_Pubs!cmboTwpNames) Or Forms!Search_Pubs!btnTownships = 0 Then
        SQLGetTownshipsPubs = ""
    Else
        TownshipString = Forms!Search_Pubs!cmboTwpNames
        Set rs = db.OpenRecordset("SELECT PUB_PUBLICATION.PUBLICATION_ID, AFRI_TWP_AREA_MSTR.TWP_AREA_NAME FROM AFRI_TWP_AREA_MSTR " _
            & "INNER JOIN (PUB_PUBLICATION_AREA INNER JOIN PUB_PUBLICATION ON " _
            & "PUB_PUBLICATION_AREA.PUBLICATION_ID = PUB_PUBLICATION.PUBLICATION_ID) ON " _
            & "CStr(AFRI_TWP_AREA_MSTR.TWP_AREA_NUM) = PUB_PUBLICATION_AREA.TOWNSHIP_AREA_NUMBER " _
            & "WHERE (((AFRI_TWP_AREA_MSTR.TWP_AREA_NAME)='" & TownshipString & "'));")
        If rs.EOF Then
            insertSQL = "insert into tblSearchResults (publication_id, publication_code, publication_title, publication_year) values (' ', ' ', 'No Publications found', ' ');"
            DoCmd.RunSQL insertSQL
            NoRecordsFlag = "true"
        Else
            rs.MoveFirst
            SQLWhereTownshipsString = ""
            Do While Not (rs.EOF)
                If Len(SQLWhereTownshipsString) < 10 Then
                    SQLWhereTownshipsString = "PUB_PUBLICATION.PUBLICATION_ID = '" & rs!PUBLICATION_ID & "'"
                Else
                    SQLWhereTownshipsString = SQLWhereTownshipsString & " OR " & "PUB_PUBLICATION.PUBLICATION_ID = '" & rs!PUBLICATION_ID & "'"
                End If
                rs.MoveNext
            Loop
        End If
    End If

    Hmmm, can't see reference to the gif I attached - if you want it email me at julian.rickards@ndm.gov.on.ca

  7. #7
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445
    Originally posted by jrickards
    No, Me doesn't work because I am running an external module so I have to reference the Form explicitly.

    Attached is a screenshot of the form in design view.

    Below is the code I am using in the module

    Code:
    If IsNull(Forms!Search_Pubs!cmboTwpNames) Or Forms!Search_Pubs!btnTownships = 0 Then
        SQLGetTownshipsPubs = ""
    Else
        TownshipString = Forms!Search_Pubs!cmboTwpNames
        Set rs = db.OpenRecordset("SELECT PUB_PUBLICATION.PUBLICATION_ID, AFRI_TWP_AREA_MSTR.TWP_AREA_NAME FROM AFRI_TWP_AREA_MSTR " _
            & "INNER JOIN (PUB_PUBLICATION_AREA INNER JOIN PUB_PUBLICATION ON " _
            & "PUB_PUBLICATION_AREA.PUBLICATION_ID = PUB_PUBLICATION.PUBLICATION_ID) ON " _
            & "CStr(AFRI_TWP_AREA_MSTR.TWP_AREA_NUM) = PUB_PUBLICATION_AREA.TOWNSHIP_AREA_NUMBER " _
            & "WHERE (((AFRI_TWP_AREA_MSTR.TWP_AREA_NAME)='" & TownshipString & "'));")
        If rs.EOF Then
            insertSQL = "insert into tblSearchResults (publication_id, publication_code, publication_title, publication_year) values (' ', ' ', 'No Publications found', ' ');"
            DoCmd.RunSQL insertSQL
            NoRecordsFlag = "true"
        Else
            rs.MoveFirst
            SQLWhereTownshipsString = ""
            Do While Not (rs.EOF)
                If Len(SQLWhereTownshipsString) < 10 Then
                    SQLWhereTownshipsString = "PUB_PUBLICATION.PUBLICATION_ID = '" & rs!PUBLICATION_ID & "'"
                Else
                    SQLWhereTownshipsString = SQLWhereTownshipsString & " OR " & "PUB_PUBLICATION.PUBLICATION_ID = '" & rs!PUBLICATION_ID & "'"
                End If
                rs.MoveNext
            Loop
        End If
    End If

    Hmmm, can't see reference to the gif I attached - if you want it email me at julian.rickards@ndm.gov.on.ca
    Are you calling the function in the module from the form when the value of the option button changes?

    I'm trying to avoid understanding all that you are doing since you mentioned that we didn't have to but I'm having difficulty seeing the flow of things. Maybe it's just 'cause it's Friday.

    Gregg

  8. #8
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Detecting which option button selected

    Originally posted by jrickards
    Hi:

    I have a search form where one of two methods may be employed to search for records on a geographic basis - townships and NTS (a geographical term, don't worry about understanding it). The user can use only one of the two methods to search for records and I have two options buttons, Townships/NTS, that determine which method is being used for the search. In both cases, the searches are via a list - if you select Townships, the list of townships appears (using the Visible=true property) and the same is true for NTS. However, in the VB code, I need to detect which method was chosen, NTS or Townships and I thought something like:

    <code>
    if Forms!Search_Pubs!btnTownships.Selected = True then ...
    </code>

    would work but it doesn't. How do I determine if a particular option button has been selected?

    TIA,
    Jules
    Jules,

    Are these option buttons in an Option Group? If they are then you determine which is seleceted from the OptionGroup's .Value property. It will have the ordinal # of the selected radiobutton ... If not, then you need to test the Value property of each radiobutton for it's trueness.

  9. #9
    Join Date
    Feb 2004
    Posts
    32
    Hi: Another message was posted before I completed this one so these comments refer to the posting prior to the one immedately above this one.

    Not exactly.

    The user completes the form with as much or as little information as they wish to use which can include type of publication (book, map or digital data), author(s), word(s) from title, date or date range and finally, geographic location. Once all of the selections have been made, they click on a "Find Publications" button which then runs the module which builds an SQL string from the selections and then performs the search, dumps the results into a results table which is then displayed in a list.

    The problem with the geographic location is that the publications are given locations using only one of two methods - townships or NTS. Townships are finer than NTS and for publications that have a large study area, they are given NTS coordinates rather than 100 or more township names. Although, technically, townships could be mapped to NTS and visa versa, the database doesn't have that facility, nor are there plans to do so. So, therefore, when searching for publications, a decision by the user must be made about whether they want to use Townships or NTS.

    Therefore my original question is - if I use the option button state or value to determine whether the user wants to search using Township or NTS, how do I get its value. I am somewhat of a newbie at this although I have made some significant progress with this search form - everything works, including the geographic search as long as I don't confuse it. Currently, if I put in a Township value and leave the NTS combo box empty, it will search on the Township - the reverse is also true but if I put in a value for both (which technically invalidates the rules I would like to set), then the SQL code fails. I would like to make this form easier to use by basing the decision on whether to search using Townships or NTS on which button was selected, not on the basis of which combo box has a value because when both have a value, it doesn't work.

    TIA,

    Jules

  10. #10
    Join Date
    Feb 2004
    Posts
    32

    Re: Detecting which option button selected

    Originally posted by M Owen
    Jules,

    Are these option buttons in an Option Group? If they are then you determine which is seleceted from the OptionGroup's .Value property. It will have the ordinal # of the selected radiobutton ... If not, then you need to test the Value property of each radiobutton for it's trueness.
    OK, I get it. Yes, they are part of an Option Group named grpGeographic but when I test Forms!Search_Pubs!grpGeographic.Value = 0, I get "can't find the field grpGeographic".

    Jules

  11. #11
    Join Date
    Feb 2004
    Posts
    32
    Me stupid!!!

    Instead of grpGeoGraphic, I typed geoGeoPraphic.

    Many thanks for your help - despite this error above, you provided a lot of good advice.

    Jules

Posting Permissions

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