Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 13th, 2005, 04:18 AM
fcm fcm is offline
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default checkbox

hi,
I have a table here with ID and Pass/Fail (checkbox)
by default the chechbox is unchecked, I want the checkbox change to checked after i fill in the ID and press a button.
how am I going to do that ?

Thanks for advance.

Reply With Quote
  #2 (permalink)  
Old April 13th, 2005, 06:56 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe you will have to set up a form to do the data entry.

You can set up the form to look like you're entering data into the table by displaying it in Datasheet view.

In the form, on the ID field, you will write an Afterupdate procedure that will check to see if the field is null and set the Pass/Fail appropriately. The following code assumes that you will want to set the Pass/Fail to false if someone clears the ID field...

Code:
If isnull(Me.ID) then
  me.PassFail = False
Else
  me.PassFail = True
End If
Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
Reply With Quote
  #3 (permalink)  
Old April 13th, 2005, 06:57 AM
Friend of Wrox
Points: 3,947, Level: 26
Points: 3,947, Level: 26 Points: 3,947, Level: 26 Points: 3,947, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,150
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Suppose you have a form with a textbox for the ID, your checkbox, and the button. Then on the button's ON CLICK event you put this (I'm using fake names since you didn't tell me yours):

Me.chkPassFail = Not IsNull(Me.txtID)

When the button is clicked, the value of the ID in the textbox txtID is evaluated to see if it's filled. If it isn't (Null) then the checkbox chkPassFail is not checked. If the ID field is filled then the checkbox is checked.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #4 (permalink)  
Old April 13th, 2005, 07:00 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Greg's shortcut code will work instead of my code. But you don't need the button if you use the Afterupdate event.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
Reply With Quote
  #5 (permalink)  
Old April 13th, 2005, 07:05 AM
Friend of Wrox
Points: 3,947, Level: 26
Points: 3,947, Level: 26 Points: 3,947, Level: 26 Points: 3,947, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,150
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by rjweers
 Greg's shortcut code will work instead of my code. But you don't need the button if you use the Afterupdate event.

True only if FCM wants the pass/fail to be checked the instant someone types in an ID. It could be that the determination for pass/fail is made later and an ID is entered beforehand (e.g. beginning of semester), so in that case you don't want it on the AFTER UPDATE event, you want to manually turn it on/off.

It is true, however, that you don't need a button. You can just have the textbox and the checkbox. Then disable the checkbox until there is an ID in the textbox.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #6 (permalink)  
Old April 13th, 2005, 07:25 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Quote:
quote:It could be that the determination for pass/fail is made later and an ID is entered beforehand...
Ah, yes. The problem we will always have... interpretting the specification.

 
Quote:
quote:I want the checkbox change to checked after i fill in the ID and press a button
I went for a simpler solution assuming that "pressing a button" was not the real trigger to the Pass/Fail update but rather the only solution that fcm could think of. I was also assuming that data entry was occuring in a table since there was no mention of a form. And if fcm is sticking with the table look and feel for data entry, a button won't display in datasheet view.

And we're both assuming that fcm wants to turn off pass/fail. There was no specification for that at all.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
Reply With Quote
  #7 (permalink)  
Old April 13th, 2005, 07:35 AM
Friend of Wrox
Points: 3,947, Level: 26
Points: 3,947, Level: 26 Points: 3,947, Level: 26 Points: 3,947, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,150
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

You are so right about interpretation. For example, I assumed a form because data entry in a shared database should never be done directly into a table. That's a big no-no. And I assumed that FCM wanted to be able to toggle the pass/fail YES/NO because people change minds, make mistakes, bribe teachers, etc. Whoops! Did I say that last one out loud?! LOL


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #8 (permalink)  
Old April 13th, 2005, 08:43 AM
fcm fcm is offline
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to both of you , Greg and Randall, Thanks a lot for the reply.
and so sorry for the insuffient explaination.
Actually i do not put any checkbox in any form.
What i want to do is after i add a record from FormA to TblA, i want the checkbox in TblB checked automatically (the key ID will link 2 both TblA and TblB)
that means I just want the computer check the checkbox after i press the button in a form which do not have any checkbox.
is that possible?

Reply With Quote
  #9 (permalink)  
Old April 14th, 2005, 05:35 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To give an answer BrianWren would be proud of me for... "Yes, it is possible".

I'd leave it at that because, as Brian likes to point out, there is barely enough description to know what the problem really is. But your first post did ask "How". So...

Two ways to accompish this... (Let's assume you're going to stay with the idea of having a button to initiate the task.)

If the recordsource for FormA can contain both tables and still be an updatable query, then Greg's method is best. The recordsource can be an updatable query where the key fields are linked. That will require an INNER join of the two tables (TblA and TblB) on the ID field. To update the checkbox (Yes/No) field, include it in the query -- this field doesn't have to display on the form for you to be able to update it in code.

The difficulty with trying to make this query work is that you're talking about "adding" records. If you can't build a query that can add a record, you'll have to find another way.

So if you can't come up with the updatable query, then you can use the Click event of the button to manipulate TblB in a variaty of ways. I tend to write SQL and use DoCmd.RunSQL to accomplish this kind of update. Code something like this.

If isnull(DLookup("ID","TblB","ID = " & Me.ID)) then
    ' TblB doesn't have the record so insert it
    Docmd.RunSQL "INSERT into TblB ([ID], [Ckbox]) Select " & Me.ID & ", True"
Else
    ' TblB has the record so update it
    Docmd.RunSQL "UPDATE TblB Set ckbox = True Where [ID] = " & Me.ID
End If

If you don't want the user to know about the Insert/Update, put
   DoCmd.SetWarnings False
before the If, and
   DoCmd.SetWarnings True
after the End If.

Now, since you say you are "adding" a record using FormA, you could use the "AfterInsert" event to "add" a record to TblB and still not need the button. If that is the case then use the DoCmd.RunSQL "INSERT Into ..." statement.

The idea that FormA only adds to TblA is a very "final" way to think about it. That is, this assumes the only possibility is that FormA adds a record to TblA. This could be the way you've designed the form. I don't often find myself writing bound forms to allow ONLY additions.

I'm not complaining about your question when I say this, but once again, you are only lightly touching on the requirement. Do you want to keep TblB synchronized with TblA? Is the relationship between TblA and TblB, one-to-many? If it is, then what happens to cause an additional record in TblB? And how do you know if the checkbox (Yes/No) of the additional record should be True or False? How do the many records of TblB relate back to TblA as far as this Yes/No field? If the relationship is one-to-one, why isn't the Yes/No field just in TblA? What happens if someone uses FormA to update TblB?

Too many questions and too little information to know what the "correct" solution is. Hopefully there is enough information in all of these posts that you'll find the way to accomplish your task.

I guess the "correct" answer to the actual question you asked is "Yes, it is possible."

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
Reply With Quote
  #10 (permalink)  
Old April 14th, 2005, 10:41 AM
fcm fcm is offline
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

rjweers u are genious! I 've got an idea how to solve my problem and you've absolutely answered my question.
Thank you very much!
To answer your questions, I have changed my form design. Actually I just want to record that whether the report is printed or not. In a form there will be a print button and as the user press the button i want the checkbox in the table to be checked.In the print button form it will not save any record into any table. Just that simple. ^_^
This forum really great and there are lots of experts here.
Once again, Thank You rjweers!

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox grstad HTML Code Clinic 1 December 18th, 2006 07:10 AM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 02:41 PM
Need Help regards checkbox nellaikumar ASP.NET 1.0 and 1.1 Basics 1 December 1st, 2005 01:07 PM
Checkbox johnjohn Classic ASP Basics 2 December 6th, 2004 05:03 PM
checkbox damnnono_86 Access 2 October 10th, 2003 03:25 AM



All times are GMT -4. The time now is 04:47 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.