Results 1 to 11 of 11
  1. #1
    nishant.dhruve is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    34

    Radio button help

    I m trying to write a code in such a way that whatever radio button are being selected will be inserted into the table with their corresponding name.This is the code what i have written so far here i m able to add employee firstname lastname and id to the table but not the selected radio button name to area of operation field




  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Can't see your code. It might be easier just to copy it into a reply here and put [CODE] tags around it.

  3. #3
    nishant.dhruve is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    34
    Private Sub cmdsave_Click()
    If optcgmp.Value = "-1" Then


    CurrentDb.Execute "INSERT INTO EmployeeI ([Area Of Operation]) VALUES('CGMP') "

    End If
    If optcoat.Value = "-1" Then

    CurrentDb.Execute "INSERT INTO EmployeeI ([Area Of Operation]) VALUES ('Coating') "
    End If

    CurrentDb.Execute "INSERT INTO EmployeeI ([Lastname],[firstname],[EMployee_ID]) VALUES ('" & Me.metxtlastname & "' , '" & Me.metxtfirstname & "' , '" & Me.metxtemp & "')"

    End Sub

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Are the radio buttons bound or unbound?
    Usually the value you've assigned to the radio button is passed to the frame that contains the buttons, thus one option only is selected. However, it looks to me as though you're using the yes/no, true/false, -1,0 values of the selected/not selected property of the radio button itself. To know which button name to include, you'll have to loop through the form controls and examine the values for controls that are only buttons and retrieve their name if they meet your selected/not selected setting.
    EDIT
    If the buttons are part of a group, it's easy enough to get the frame value. Based on that, you know which button has been selected, thus it is easier to get its name.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    nishant.dhruve is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    34
    Those are unbound and not grouped buttons but when i trying to pass the value for area of operation when radio button is active that value is not showing up in the table expect that everything including firstname lastname is passed into table.
    so i m trying to figure out that the way to get values of radio button into the table

  6. #6
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    I think you first said you wanted the radio button name.
    I m trying to write a code in such a way that whatever radio button are being selected will be inserted into the table with their corresponding name.
    Now you are saying you want the radio button value.
    when radio button is active that value is not showing up in the table
    I'm confused about what it is that you want.

    This will provide the name and value of an option button if it is not Null and not 0 (the only other possible value is -1) and not part of an option frame. Different code is required if the buttons are part of an option group.
    Code:
    Dim ctl As Control
    
    For Each ctl In Me.Controls
      If ctl.ControlType = acOptionButton Then
        If ctl.Value = -1 Then MsgBox ctl.Name & ": " & ctl.Value
      End If
    Next
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    nishant.dhruve is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    34
    ok let me explain in everything in clear manner

    SO this is my form now as u can see there are 3 field where one have to type and those type values are passed into related table.
    Now along with this i want that when i click save button it should also take name of radio button for example General Prod to table in the field name as areaofoper(table is shown below). Can u help me on this??

  8. #8
    nishant.dhruve is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    34
    Ok so let me clear you confusion
    I have 4 filed in my form out of which three are text field and one is of Radio button.
    So here now i m able to get my name into table whatever i m writing into those text field but i m not able to save the name realted to radio button in the table.
    I need a code for that.

  9. #9
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    If you posted an image, it didn't work. I posted the code for getting the button name in my last post, but after reviewing your previous posts, I think you were showing you already knew how to get that. The problem may be that -1 is a number, so you must NOT wrap it in quotes: If optcgmp.Value = -1
    To use the radio button name, it is Me.buttonName. However, when the form first opens, the unbound button value is NULL, so you have to watch for that. It is only -1 if it has been selected, and is zero if it was selected then was deselected. However, I think your problem all along has been the quotes around the -1.
    i m not able to save the name
    This could mean a bunch of things: query not working, code to write query not being executed, can't figure out how to reference the button name and use it, etc.
    Last edited by Micron; 08-10-2016 at 05:37 PM. Reason: c

  10. #10
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Looks like another double posting
    https://www.accessforums.net/showthread.php?t=61343

  11. #11
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Go back to your code as shown in post #3. You have 3 distinct Insert Into ... statements, which inserts up to three new records. The last one inserts a record with the employee last name, first name and ID, but it does not include the Area of operation. If you want the Area of Operation to be in the same record as the name and ID, it has to be in the same INSERT statement as Names and ID.

    You can also use an INSERT statement for the name and ID, and then an UPDATE statement to add the Area of Operation to the same record.

    your code seems to indicate that there can be more than one Area of Operation for the same Employee - is that correct? If so, you need to take a look at your data structure - it is not properly normalised.

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

Similar Threads

  1. Radio button in form
    By Xterra14s in forum Access
    Replies: 2
    Last Post: 06-09-2016, 11:04 AM
  2. Radio Button Question
    By data808 in forum Access
    Replies: 2
    Last Post: 05-10-2014, 01:27 AM
  3. Uncheck Radio Button?
    By taimysho0 in forum Programming
    Replies: 2
    Last Post: 06-29-2012, 03:44 PM
  4. radio button and checkbox
    By Fifa in forum Access
    Replies: 2
    Last Post: 01-19-2011, 10:20 AM
  5. Select Radio Button and another one turns off
    By Lockrin in forum Programming
    Replies: 1
    Last Post: 02-09-2010, 02:17 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