Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Changing values for a checkbox on an excel form


Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2003, 02:11 PM
TomGuy's Avatar
TomGuy TomGuy is offline
Junior Contributor
 
Join Date: Sep 2001
Location: Igloo # 7, Canada
Posts: 332
Default Changing values for a checkbox on an excel form


Hi,

I'm using VB6 to populate an Excel file that I've created. The Excel file has a few controls on it, including some checkboxes. This is the code I'm using to populate the checkboxes:
Code:
Dim Index As Integer Index = 1 Dim obExcelApp As Excel.Application Dim obWorkBook As Excel.Workbook Set obExcelApp = CreateObject("Excel.Application") Set obWorkBook = obExcelApp.Workbooks.Open("C:\WINDOWS\SYSTEM\Sales Order Template.xlt") obWorkBook.Worksheets(Index).chkCheque.Value = True ' Save as a temporary file to save the template and show the temp file obWorkBook.SaveAs ("C:\tempsales.xls") obExcelApp.Visible = True ' clear the variables Set obWorkBook = Nothing Set obExcelApp = Nothing
When the excel file opens though, the checkboxes don't visually appear to be checked. They are checked, however, if I messagebox their values. Also, once the form is open, the first time that I try to check (enable) them, they flash checked but remain unchecked. After that they work normally (going from checked to unchecked)....It's as if the form is not being refreshed when it first loads.

If you can help me out, it would be greatly appreciated.

Thanks a bunch,

Tom
__________________
If vegetarians eat vegetables, watch out for humanitarians...
Reply With Quote
  #2  
Old 03-12-2003, 04:37 PM
Legend Legend is offline
Contributor
 
Join Date: Dec 2002
Posts: 542
Default

You could try getting the workbook to refresh (obWorkBook.RefreshAll) - - can't try it myself at the moment though
Reply With Quote
  #3  
Old 03-13-2003, 06:49 AM
TomGuy's Avatar
TomGuy TomGuy is offline
Junior Contributor
 
Join Date: Sep 2001
Location: Igloo # 7, Canada
Posts: 332
Default

Thanks for the suggestion but unfortunately it didn't work.

Any other ideas?
__________________
If vegetarians eat vegetables, watch out for humanitarians...
Reply With Quote
  #4  
Old 03-13-2003, 10:53 AM
TomGuy's Avatar
TomGuy TomGuy is offline
Junior Contributor
 
Join Date: Sep 2001
Location: Igloo # 7, Canada
Posts: 332
Default

Is there a way to force the checkboxes to appear visually correct?...maybe a 2-step process even?

Any help greatly appreciated.

Thanks!
__________________
If vegetarians eat vegetables, watch out for humanitarians...
Reply With Quote
  #5  
Old 03-14-2003, 06:18 AM
TomGuy's Avatar
TomGuy TomGuy is offline
Junior Contributor
 
Join Date: Sep 2001
Location: Igloo # 7, Canada
Posts: 332
Default

Anyone?
__________________
If vegetarians eat vegetables, watch out for humanitarians...
Reply With Quote
  #6  
Old 03-14-2003, 01:19 PM
nighthawk nighthawk is offline
Junior Contributor
 
Join Date: Jun 2001
Location: WV
Posts: 280
Default

Heres the work around I ended up with for the same problem:

1) Pick a row that will not be used for your work book
2) Right Click on the Checkbox
3) Select Format Control
4) On the control tab you'll see a cell link field
5) Assign the checkbox to a cell in the row you chose
6) Do this for each checkbox giving them each a different cell in the row
7) Now you can put the value True or False into the cells
8) The checkboxes will respond accordingly


Just to note I selected the row and hid it so the user would not see the value. I just change the values in the hidden row using VB and the correct checkboxes become highlighted. It works great for me.
Reply With Quote
  #7  
Old 03-14-2003, 01:37 PM
TomGuy's Avatar
TomGuy TomGuy is offline
Junior Contributor
 
Join Date: Sep 2001
Location: Igloo # 7, Canada
Posts: 332
Default

That worked great! I didn't even think of using Form controls. I was using controls from the Control Toolbox because I was trying to refer to their names through code. Using the Form controls and then just linking them with cells on the form is a great idea!

Thanks a bunch!

Tom
__________________
If vegetarians eat vegetables, watch out for humanitarians...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a form default all field values to the previous records values ? vbad Database and Reporting 1 11-25-2002 01:35 PM
Refresh Label Caption in Form (Excel) Molitor Word, PowerPoint, Outlook, and Other Office Products 1 10-24-2002 01:02 PM
How can I check for duplicates before saving a new record GOTzMADsKILLz Database and Reporting 19 08-15-2002 11:56 AM
Checkbox on Excel VBA Form Tommy Gun Word, PowerPoint, Outlook, and Other Office Products 2 02-12-2002 04:34 PM
Create a new form similar to an existing form ric General 6 07-17-2001 12:47 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->