Results 1 to 8 of 8
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    how to insert gender (male/female) option group in sql INSERT INTO statement

    Hi,
    I have the following:
    #
    CurrentDb.Execute _
    "INSERT INTO [Members] (" & _
    "[Family Name], " & _
    "[First Name], " & _
    "[Date of birth], " & _
    "[Gender]" & _
    "[MobilePhone]" & _
    "[eMail]" & _
    "[Comments]" & _
    ") VALUES (" & _
    "'" & Me.FamilyNameTxt & "', " & _
    "'" & Me.FirstNameTxt & "', " & _
    "#" & Me.DoBTxt & "#, " & _
    "'" & MaleOrFemale & "'" & _
    "'" & Me.PhoneTxt & "'" & _
    "'" & Me.EmailTxt & "'" & _
    "'" & Me.CommentsTxt & "'" & _
    ")"
    #

    On my form the Gender Option Group is Frame27
    the Option Buttons are Option30 (Female) Option Value: -1
    Option32 (Male) Option Value: 0

    Don't know how to get the value (MaleOrFemale) from the option group.


    Any help appreciated.
    Thanks
    David

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    You reference the option group frame control name. The frame takes the value of the selected button in the group.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,740
    Are you saying/asking that you want 3 possible values, such as

    Option30 (Female) Option Value: -1
    Option32 (Male) Option Value: 0
    Option34 (MaleOrFemale) Option Value: 1

    June has provided info re the selected value in the Frame.

    Good luck.

  4. #4
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Thanks for this, still having problems. I want M or F to appear in Gender so I added the following before the INSERT statement:
    #
    Dim MorF As String
    MorF = "M"
    If Me.Frame27 = "-1" Then
    MorF = "F"
    End If
    #

    I've corrected formatting and replaced MaleOrFemale in the INSERT statement with MorF.

    The Insert works without error

    But for Gender I only receive "0"

    What am I missing?

    Thanks
    David

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Don't put -1 in quote marks.

    One liner

    MorF = IIf(Me.Frame27 = -1, "F", "M")

    Or use a combobox with 2 choices.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,740
    David,
    Instead of "'" & MaleOrFemale & "'" & _

    Try this line
    IIf(Me.Frame27 = 0, "M", "F") & _

    and instead of
    CurrentDb.Execute _

    try Debug.print _ to see what Access understands.

    I think you are missing some commas to separate the field values, but lets see what the Debug.print (debugging) shows.

    OOOps: June has already responded.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Yep. Definitely missing commas for 3 pairs of fields and inputs.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi, Thanks all - problem was had Gender defined as Yes/No field, changed to Short Text all OK

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

Similar Threads

  1. Insert a group of records.
    By ep4tech in forum Forms
    Replies: 6
    Last Post: 10-25-2018, 02:29 PM
  2. Insert into with a WHERE statement
    By hazeleyre23 in forum Access
    Replies: 10
    Last Post: 04-06-2016, 08:28 AM
  3. Option Group for gender
    By hamidchi in forum Forms
    Replies: 3
    Last Post: 08-23-2015, 12:07 PM
  4. Choice of Male or Female. What data type to use?
    By Access_Novice in forum Access
    Replies: 5
    Last Post: 09-19-2013, 09:06 PM
  5. Insert Into statement
    By TimMoffy in forum Programming
    Replies: 7
    Last Post: 07-13-2012, 07:10 AM

Tags for this Thread

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