Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA CheckBoxes

Status
Not open for further replies.

RiderJon

Programmer
Aug 26, 2002
190
FR
Hi:

I want to write a code for a "Check-Box" based on a data within a SubReport.

The problem I have is referring to the dataSource eg:

If tbl.Val = "0000" Then
chkID = True
End If

But I get an error for the "If tbl.Val = "0000")


Any suggestion?
 
gotcha. Thank you. Sure has been quite a learning experience. haha. Back to good 'ol queries then.
 
Don:
Oops, the "s" my typo here not in code.
What do you mean by control and coversion function? (yes, I am new to VBA).

Don/Allanon:
I am faced with the same referencing problem. Made a "NEw" report. Trying to make a check box based on the same data as above: logically Stated if ("val"="0000") OR ("val"="0354") then "highlight the check-box called "chkID".
Else
Highlight the checkbox "chkDes".

I get the same referencing problem even when using variants of "Me" .... "Reports!....." ..... says "can't find the field". Check boxes suck!
 
Can you send me a db with just the table and the report.

jdyck@wcb.mb.ca

I will look at it. If you are in the same repor tit whould work.
 
Actually Allanon, can you post or send me a sample code for "referencing a report field. Problem is the data is confidential and it is a very huge file (d757b@yahoo.com).

Thank you.

 
RiderJon,

Is the check box on the main report, and val on the subreport??

Try this in the detail section of your main report, of course changing control names where needed:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Select Case Reports![MainReport]![SubReport]!val
Case "0000"
     Me.chkID = True
     Me.chkDes = False
Case "0001"
     Me.chkID = True
     Me.chkDes = False
Case Else
     Me.chkDes = True
     Me.chkID = False
End Select
End Sub
If this doesn't work, it's probably real close......
 
CosmoKramer:

I just included a "text-box" displaying the data "val" -- right above my check boxes. Somehow that "binded" the Me.Val and it worked. Also, I made the textbox invisible so that I don't double represent the data.

Anyway, just to know: Is it possible to use a CheckBox INSIDE a subreport (and not the main report)-- that uses data from the same subreport? If so, can you post a few link or code.
 
Sure, you should be able to do it in the detail section of your subreport, using the Me property. It would be something like this:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.val = "0000" Or Me.val = "0354" Then
   Me.Check1 = True
Else
   Me.Check1 = False
End If
End Sub
 
Cosmo:

Thanx for the help. It does work. However when the viewing the report and "jumping" to the next page gives a run-time error.

"You have entered an expression that has no value".

But when I check for NULL and debug, it nevers enters the "NULL check" and instead quits after the 6th record (which also happens to be beginning of my 2nd page in Report.

Here's the code (based on your's):

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim strinput As String

'srpID = subreport; and val is the Data Field IN srpID.
strinput = Me!srpID!Val

If strinput = Null Then
strinput = "0000"
End If

Select Case strinput
Case "0000"
chkID = True
chkDes = False
'If Both
Case "0354"
chkDes = True
chkCCF = True
Case Else
chkCCF = False
chkDes = True
End Select

End sub

To All, thank you for -any and all - the help so far.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top