Results 1 to 18 of 18

Thread: Option Button "Value" [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Option Button "Value" [RESOLVED]

    I have three option buttons that I am trying to work with in a sql INSERT INTO statement. I name the db field and then where I need to insert the value of the option box, I keep getting an error message either about an undeclared variable or an illegal qualifier. Can someone help me w/ the syntax for an option button value. Cannot find any MS documentation dealing w/ this. I have declared OptCtrtType As Control. Thanks for any help. --Ed
    Last edited by StLMacMan; Feb 23rd, 2005 at 07:36 PM. Reason: Resolved

  2. #2
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Option Button "Value"

    Yuo need to post some code.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    The option buttons or checkboxes will usually give you this error when you rely on the
    default property of the control instead of explicitly stating the property.

    VB Code:
    1. "INSERT INTO Table1 VALUES (" & optOption1.Value & ")"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Re: Option Button "Value"

    David, I'm still working on the "blank" date problem. Someone suggested using a Null replacement for any date showing "##", so I've been trying to get that to work. I'll try to figure out how to only have the user see a blank when they review the file and there has been a Null entry in the db, but first I have to get it to save the Null.--Ed

    Here's the code:
    VB Code:
    1. Private Sub CmdSave_Click()
    2. Dim INSERTStmt As String
    3. Dim OptCtrtType As Control
    4.  
    5. Set Con = New ADODB.Connection
    6.     Set rs = New ADODB.Recordset
    7.     Con.Open strCon
    8.    
    9. INSERTStmt = "INSERT INTO Contract (Corps_Institution, Program, Funder, " & _
    10. "Contract_Amount, Contract_Number, Start_Date, End_Date, Contract_Type, " & _
    11. "Application_Submission, Face_Sheet_Completed, Received_in_SS_Dept, " & _
    12. "Presented_to_DFB, Sent_to_THQ, Received_from_THQ, Sent_to_Funder_or_Unit, " & _
    13. "Executed_Copy_received_from_Funder, Executed_Copy_sent_to_THQ_and_Unit, Filed)" & _
    14. "VALUES ('" & CboUnit.Text & "', '" & CboProgram.Text & "', '" & CboFunder.Text & "', " & _
    15. "'" & TxtCtrtDollarAmount.Text & "', '" & TxtCtrtNo.Text & "', #" & TxtCtrtStartDate.Text & "#, " & _
    16. "#" & TxtCtrtEndDate.Text & "#, '" & OptCtrtType.Value & "', " & _
    17. "#" & TxtAppDate.Text & "#, #" & TxtFaceSheetCompleted.Text & "#, #" & TxtReceivedBySSDept.Text & "#, " & _
    18. "#" & TxtSubmittedToDFB.Text & "#, #" & TxtSentToTHQ.Text & "#, #" & TxtReceivedFromTHQ.Text & "#, " & _
    19. "#" & TxtSentToFunder.Text & "#, #" & TxtExecutedCopyReceivedFromFunder.Text & "#, " & _
    20. "#" & TxtExecutedCopySentToTHQ.Text & "#, #" & TxtFiled.Text & "#)"
    21.  
    22. INSERTStmt = Replace(INSERTStmt, "##", "NULL")
    23.  
    24. Con.Execute "INSERT INTO Contract (Corps_Institution, Program, Funder, " & _
    25. "Contract_Amount, Contract_Number, Start_Date, End_Date, Contract_Type, " & _
    26. "Application_Submission, Face_Sheet_Completed, Received_in_SS_Dept, " & _
    27. "Presented_to_DFB, Sent_to_THQ, Received_from_THQ, Sent_to_Funder_or_Unit, " & _
    28. "Executed_Copy_received_from_Funder, Executed_Copy_sent_to_THQ_and_Unit, Filed)" & _
    29. "VALUES ('" & CboUnit.Text & "', '" & CboProgram.Text & "', '" & CboFunder.Text & "', " & _
    30. "'" & TxtCtrtDollarAmount.Text & "', '" & TxtCtrtNo.Text & "', #" & TxtCtrtStartDate.Text & "#, " & _
    31. "#" & TxtCtrtEndDate.Text & "#, '" & OptCtrtType.Value & "', " & _
    32. "#" & TxtAppDate.Text & "#, #" & TxtFaceSheetCompleted.Text & "#, #" & TxtReceivedBySSDept.Text & "#, " & _
    33. "#" & TxtSubmittedToDFB.Text & "#, #" & TxtSentToTHQ.Text & "#, #" & TxtReceivedFromTHQ.Text & "#, " & _
    34. "#" & TxtSentToFunder.Text & "#, #" & TxtExecutedCopyReceivedFromFunder.Text & "#, " & _
    35. "#" & TxtExecutedCopySentToTHQ.Text & "#, #" & TxtFiled.Text & "#)"
    36.  
    37.     Con.Close
    38.     Set Con = Nothing
    39.    
    40. End Sub

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    In order to get it to see a null in a date field you can set the fields required to No and
    just dont include it in the insert statement. Passing a Null will be the same as not including
    it as long as the required is No.

    But a better way may be to include an imediate if statement for each date field that could
    contain a null date. Then if its null just return a vbnullstring else return the formatted date
    wrapped with "#"'s.?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Re: Option Button "Value"

    Rob, actually I'd rather not see the Null. This whole problem arose because I built the form, tested it with complete data, and then recognized that it will be used w/ several date fields empty initially and then filled in periodically over time. I'd like for the blank fields to show up as blank when the user searches for the saved data later. Then they can edit and save again. However, I have been unable to figure out how to save a blank date field to Access, have read and heard from others that it can't be done, so leaving out the empty fields might get me what I need. I can't figure out how to efficiently write conditionals to only include the date fields w/ data in them. There are 10 date fields on the form and only about 3 or 4 will be used initally. Over time they will all be filled in as the events they record transpire. What do you think? --Ed

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    Probably adjusting (if its not already) the date fields to allow zero lenth and so they are
    not required. Then in you presentation to the form check for null or "12:00" values and parse
    them out before it gets to the textboxes, etc. This will help also if they are doing any updating
    on the records too.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Re: Option Button "Value"

    Can you tell me what you mean by "parse out" the null value date fields?

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    When you read a record back in for displaying it to the user, the date field will be
    "null" but may in fact display a "value" of 12:00 AM. This is sometimes the value
    that is returned instead of just the Null youd expect. It has to do with the field
    data type being a date/time field.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Re: Option Button "Value"

    So if it is saved to the db as Null can I write something that will cause it to return a blank for the user to see when they do a search for the record?

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Option Button "Value"

    We use MS SQL SERVER, and allowing dates to be NULL is one of the most frequent uses we make of NULL values in a database.

    Date fields that are not permitted to be NULL end up having a value - in SQL it's 01/01/1900. That's a really bad value to have for a "blank" date.

    Whenever we get a recordset from the database, we convert all DATES to STRINGS (see the link in my signature for SQL Rules to Live by - you'll see what we do with CONVERT() for dates). We treat all DATES on the VB side as strings - so simply doing RS(column).VALUE & "" will turn a NULL string into an "empty" string - so a text box can retain that value.

    Works for us!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    Yes that is a valid workaround szlamany, but StLMacMan dont forget that you will
    need some date validation to make sure it a real date.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Re: Option Button "Value"

    Since I'm mandated to use Access 2002, am I correct that I can use its date notation to save the Null and then convert it back to a string and then use & "" to display the blank date on the user's form when he calls the record?

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    You may be better off setting your field's data type to text. Then you can use
    the logic mentioned for "" as nulls.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Re: Option Button "Value"

    I'm thinking through the date issue, but still cannot get past the syntax problem for the option buttons. Here's my code

    VB Code:
    1. Private Sub OptCtrtNew_Click()
    2. Dim CtrtType As String
    3. If OptCtrtNew.Value = True Then
    4. CtrtType = "New"
    5. ElseIf OptCtrtRenewal.Value = True Then
    6. CtrtType = "Renewal"
    7. ElseIf OptCtrtAmendment.Value = True Then
    8. CtrtType = "Amendment"
    9. End If
    10. End Sub

    I am then trying to do and INSERT INTO sql string that captures "New," "Renewal," or "Amendment" depending on the button selected. I have tried about a bazillion different attempts at syntax (none of which work) with the lastest being:

    VB Code:
    1. Private Sub CmdSave_Click()
    2. Dim INSERTStmt As String
    3. Dim CtrtType As String
    4. Set Con = New ADODB.Connection
    5.     Set rs = New ADODB.Recordset
    6. Con.Open strCon
    7. Con.Execute "INSERT INTO Contract (. . .Contract_Type, . . .)"  & _
    8. "VALUES (. . . '" & CtrtType.Text & "', . . .)"
    9.  
    10.     Con.Close
    11.     Set Con = Nothing
    12.    
    13. End Sub

    Apparently "CtrtType" cannot be a String if it modiefies .text. I've tried Dimming it as an OptionButton and an Object as well, but get either a type mismatch or a With Block or variable not defined message. I don't see what to do to make this work. "Help" did not help. Any human help appreciated. --Ed

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    VB Code:
    1. Option Explicit
    2.  
    3. Dim CtrtType As String
    4.  
    5. Private Sub OptCtrtNew_Click()
    6.     'Dim CtrtType As String
    7.     If OptCtrtNew.Value = True Then
    8.         CtrtType = "New"
    9.     ElseIf OptCtrtRenewal.Value = True Then
    10.         CtrtType = "Renewal"
    11.     ElseIf OptCtrtAmendment.Value = True Then
    12.         CtrtType = "Amendment"
    13.     End If
    14. End Sub
    15.  
    16. Private Sub CmdSave_Click()
    17.     Dim INSERTStmt As String
    18.     'Dim CtrtType As String
    19.     Set Con = New ADODB.Connection
    20.     Set rs = New ADODB.Recordset
    21.     Con.Open strCon
    22.     Con.Execute "INSERT INTO Contract (. . .Contract_Type, . . .)"  & _
    23. "VALUES (. . . '" & CtrtType & "', . . .)"
    24.  
    25.     Con.Close
    26.     Set Con = Nothing
    27.    
    28. End Sub
    You declaring the CtrtType in multiple places, thus your clearing out the value from the opt click event. Make it modular by declaring in the declarations section.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Member
    Join Date
    Feb 2005
    Location
    St. Louis
    Posts
    39

    Re: Option Button "Value"

    Thanks, Rob. That did the trick on the Option Button value. Now I'm going to focus on the blank date problem. Thanks again--Ed.

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Option Button "Value"

    No prob. Glad to help. It keeps me sharp

    ps, dont forget to Resolve your thread
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width