473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Cant assign a value to this object ... when trying to clear a checkbox

I have a piece of code which resets all the control on a form ..but if
I also put an option group on the form and the relevant code in the
routine to reset it I get an error message saying that you cant assign
a value to this object when the code reaches the line for the checkbox.
The code works perfectly if EITHER option group or checkbox are in BUT
not when both are in

Any suggestions please

Public Sub ClearForm()
Dim frm As Form
Dim ctl As Control
Set frm = Screen.ActiveForm

For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Then
ctl.Value = ""
End If
If ctl.ControlType = acListBox Then
ctl.Value = Null
End If
If ctl.ControlType = acComboBox Then
ctl.Value = Null
End If
If ctl.ControlType = acCheckBox Then
ctl.Value = 0

End If
Next
End Sub

Many Thanks AnnBB

Feb 8 '06 #1
1 2319
The controls (check boxes or option buttons or whatever) that are part of
the option group do not have a Value, so you cannot set them.

Either check the Parent of the control to see if it is the option group, or
use error handling to resume on the next line.

BTW, setting a text box to a zero-length string is probably less desirable
than setting it to Null.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"annbb" <an***@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I have a piece of code which resets all the control on a form ..but if
I also put an option group on the form and the relevant code in the
routine to reset it I get an error message saying that you cant assign
a value to this object when the code reaches the line for the checkbox.
The code works perfectly if EITHER option group or checkbox are in BUT
not when both are in

Any suggestions please

Public Sub ClearForm()
Dim frm As Form
Dim ctl As Control
Set frm = Screen.ActiveForm

For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Then
ctl.Value = ""
End If
If ctl.ControlType = acListBox Then
ctl.Value = Null
End If
If ctl.ControlType = acComboBox Then
ctl.Value = Null
End If
If ctl.ControlType = acCheckBox Then
ctl.Value = 0

End If
Next
End Sub

Many Thanks AnnBB

Feb 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
4
by: Terry | last post by:
I have a number of input boxes used to display totals based on selected items for each row in a table. There are more than a few rows that are identical, except for the form field name. I have...
3
by: Sarah West | last post by:
Hi, I have the following problem; This is my form, i would like to default the select box to USA, and default the text field to a name such as 'Sarah' and the hidden field to another number...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
6
by: Alan Silver | last post by:
Hello, I am data binding a repeater that has a checkbox in the ItemTemplate. The data value coming out of the database is a char(1) field containing either "y" or "n". I want to use this value...
6
by: Jerry Camel | last post by:
Basic Web Form... A few text boxes and a checkbox - and a card reader... The effect I want to accomplish is this: The basic credit card fields are there and can be filled out. But if the user...
16
by: Mike Fellows | last post by:
when i load my windows form i populate a combobox i use the code below Dim conn As New System.Data.SqlClient.SqlConnection(strConn) Dim sql As String = "AllLenders" Dim da As New...
4
by: Avi | last post by:
Hi I am creating web application in which i want to assign by default values to the property which i had created my own. In that one of the property is of type color and i am unable to assign...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.