Best way

A

Afrosheen

Thanks for reading my post.

I have two forms. One displays "Print All Reports" it has in it, "A-Rotation
and B-Rotation". It will print out 4 reports. This works ok. The other form
is called: Rotation Select. In it it has A-Days, A-Nights, B-Days, &
B-Nights. This works fine.

Lets stay with two button A-Days and A-Nights. The others will be the same.
What I'd like to do is once A-days is pressed it sets a variable that can be
used in the Print All Reports form. So once it is pressed then the A_Rotation
button will either be disabled. That way the A-Night shift will not be able
to print out the reports from the day shift.

When the night shift comes on and selects A-Nights from the Rotation Select
it sets a variable that can be use in the Print All Reports form so the day
shift will not be able to print the night shift reports.

Any suggestions? And how would I code it.

Thanks
 
J

Jeanette Cunningham

Afrosheen
One way is to put an unbound and hidden checkbox on the form.
Clicking the A rotation button sets the checkbox to True.
Clicking the B rotation button sets the checkbox to False.

Code something like this:

Private Sub cmdA-Days_Click()
Me.NameOfCheckBox = True

Private Sub cmdA-Nights_Click()
Me.NameOfCheckBox = True


The other form checks the value of the checkbox on the other form.
If Forms!NameOfForm!NameOfCheckBox = True then
Me.cmdA-Rotation.Enabled = False
'code to print only reports for days
Else
Me.cmdA-Rotation.Enabled = True
'code to print only reports for nights
End If

The form with the hidden checkbox must be open at the other form wants to
check the value in the checkbox.

An alternative way is to use a hidden but open form and put the unbound
hidden checkbox there.
You may already have a hidden form that is always open, if you have, use it,
otherwise create a hidden form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
A

Afrosheen

Sorry for the slow reply and thanks for taking my question.

Is it possible to create another table with just the checkbox field then
when I click on A-days it will put the check mark in the check box in that
table. When I go to print the code checks to see if there's a checkmark in
the check box and then highlight just the A-day print routine? If this will
work then will this code work?

Me.tblconfig.[abn] = True

This is the table where the checkbox is located.

Thanks
 
J

Jeanette Cunningham

You can update the checkbox field using a query like this.

--------------------
Dim strSQL As String

If Me.NameOfCheckBox = True Then
strSQL = "UPDATE tblconfig '"_
& "SET tblconfig.abn = True"

Else
strSQL = "UPDATE tblconfig '"_
& "SET tblconfig.abn = False"
End If

CurrentDb.Execute strSQL, dbFailOnError
-------------------

To check before printing, use code something like this
-------------------
Dim bolPrintA as Boolean

bolPrintA = Nz(DLookup("[abn]", "tblconfig"),False)

If bolPrintA = True Then
'code here to print the correct records
Else
'print the other records
End If
------------------

You will also need to reset tblconfig.[abn] to False
before you run the print process again.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Afrosheen said:
Sorry for the slow reply and thanks for taking my question.

Is it possible to create another table with just the checkbox field then
when I click on A-days it will put the check mark in the check box in that
table. When I go to print the code checks to see if there's a checkmark in
the check box and then highlight just the A-day print routine? If this
will
work then will this code work?

Me.tblconfig.[abn] = True

This is the table where the checkbox is located.

Thanks


Jeanette Cunningham said:
Afrosheen
One way is to put an unbound and hidden checkbox on the form.
Clicking the A rotation button sets the checkbox to True.
Clicking the B rotation button sets the checkbox to False.

Code something like this:

Private Sub cmdA-Days_Click()
Me.NameOfCheckBox = True

Private Sub cmdA-Nights_Click()
Me.NameOfCheckBox = True


The other form checks the value of the checkbox on the other form.
If Forms!NameOfForm!NameOfCheckBox = True then
Me.cmdA-Rotation.Enabled = False
'code to print only reports for days
Else
Me.cmdA-Rotation.Enabled = True
'code to print only reports for nights
End If

The form with the hidden checkbox must be open at the other form wants to
check the value in the checkbox.

An alternative way is to use a hidden but open form and put the unbound
hidden checkbox there.
You may already have a hidden form that is always open, if you have, use
it,
otherwise create a hidden form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
A

Afrosheen

Hi Jeanette,
Here is what I entered:

Dim strSQL As String
strSQL = "UPDATE tblconfig '" & "SET tblconfig.adn = True"
CurrentDb.Execute strSQL, dbFailOnError

I just used the first part because all I need is the check box "abn"in
tblconfig checked. Then when I go to print our the report it will check the
status of "abn" in tblconfig to see if its true or false. That's where the
second part of the programming comes in.

I kept getting this error
Error 3125: "set tblconfig.abn=true' is not a valid name. make sure that it
does not include invalid characters or punctuation and that its not too long.

Thanks again

Jeanette Cunningham said:
You can update the checkbox field using a query like this.

--------------------
Dim strSQL As String

If Me.NameOfCheckBox = True Then
strSQL = "UPDATE tblconfig '"_
& "SET tblconfig.abn = True"

Else
strSQL = "UPDATE tblconfig '"_
& "SET tblconfig.abn = False"
End If

CurrentDb.Execute strSQL, dbFailOnError
-------------------

To check before printing, use code something like this
-------------------
Dim bolPrintA as Boolean

bolPrintA = Nz(DLookup("[abn]", "tblconfig"),False)

If bolPrintA = True Then
'code here to print the correct records
Else
'print the other records
End If
------------------

You will also need to reset tblconfig.[abn] to False
before you run the print process again.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Afrosheen said:
Sorry for the slow reply and thanks for taking my question.

Is it possible to create another table with just the checkbox field then
when I click on A-days it will put the check mark in the check box in that
table. When I go to print the code checks to see if there's a checkmark in
the check box and then highlight just the A-day print routine? If this
will
work then will this code work?

Me.tblconfig.[abn] = True

This is the table where the checkbox is located.

Thanks
 
J

John W. Vinson/MVP

Hi Jeanette,
Here is what I entered:

Dim strSQL As String
strSQL = "UPDATE tblconfig '" & "SET tblconfig.adn = True"
CurrentDb.Execute strSQL, dbFailOnError

I just used the first part because all I need is the check box "abn"in
tblconfig checked. Then when I go to print our the report it will check the
status of "abn" in tblconfig to see if its true or false. That's where the
second part of the programming comes in.

You're inserting an extra quotemark. I'm guessing you got it from a
post explaining how to generate a criterion on a text field but you
certainly don't need a quotemark after tblconfig. Try

strSQL = "UPDATE tblconfig SET tblconfig.adn = True"

if you want to update *every single record* in tblConfig.
 
A

Afrosheen

Hi John and Jeanette,
I've got the first part of the routine working where it will add the check
mark in the checkbox. Now I'm working on the second part and I'm getting an
error. I'm checking to see if the tblconfig [adb] is checked or not. Here is
the code:

Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

MsgBox bolPrintA
End Sub

The error I'm getting is: Label not defined.

Thanks again
 
A

Afrosheen

Update:
I need to check the tblconfig [adn] when the form first opens or loads. When
ever I placed the code in the On open or On load event even with no code both
will give me the error.

Thanks

Afrosheen said:
Hi John and Jeanette,
I've got the first part of the routine working where it will add the check
mark in the checkbox. Now I'm working on the second part and I'm getting an
error. I'm checking to see if the tblconfig [adb] is checked or not. Here is
the code:

Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

MsgBox bolPrintA
End Sub

The error I'm getting is: Label not defined.

Thanks again
John W. Vinson/MVP said:
You're inserting an extra quotemark. I'm guessing you got it from a
post explaining how to generate a criterion on a text field but you
certainly don't need a quotemark after tblconfig. Try

strSQL = "UPDATE tblconfig SET tblconfig.adn = True"

if you want to update *every single record* in tblConfig.
 
J

Jeanette Cunningham

Assuming that there is ever only one record in tblconfig.
Is the field called adn or abn or adg or something else?
You must use the correct name for the field in the table.
In the code below, make sure you use the correct name for it.

Let's put in a debug.print to see what access finds as it goes through the
code.
Debug.Print gives you a record of what access found in the immediate window.
So open the form with the code below.
When access runs the lines that begin with Debug.Print, it prints the result
to the immediate window.
When the form errors, close the form and press Ctl + G to open the immediate
window.
If access found a value you will see something like
lookup: True

If access couldn't find a value for the lookup you will see
lookup:
Similarly for bolPrintA


Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
Debug.Print "lookup: " & DLookup("[adn]", "tblconfig")

bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

Debug.Print "bolPrintA: " & MsgBox bolPrintA
End Sub




Afrosheen said:
Update:
I need to check the tblconfig [adn] when the form first opens or loads.
When
ever I placed the code in the On open or On load event even with no code
both
will give me the error.

Thanks

Afrosheen said:
Hi John and Jeanette,
I've got the first part of the routine working where it will add the
check
mark in the checkbox. Now I'm working on the second part and I'm getting
an
error. I'm checking to see if the tblconfig [adb] is checked or not. Here
is
the code:

Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

MsgBox bolPrintA
End Sub

The error I'm getting is: Label not defined.

Thanks again
John W. Vinson/MVP said:
On Mon, 21 Jul 2008 17:26:00 -0700, Afrosheen

Hi Jeanette,
Here is what I entered:

Dim strSQL As String
strSQL = "UPDATE tblconfig '" & "SET tblconfig.adn = True"
CurrentDb.Execute strSQL, dbFailOnError

I just used the first part because all I need is the check box "abn"in
tblconfig checked. Then when I go to print our the report it will
check the
status of "abn" in tblconfig to see if its true or false. That's where
the
second part of the programming comes in.

You're inserting an extra quotemark. I'm guessing you got it from a
post explaining how to generate a criterion on a text field but you
certainly don't need a quotemark after tblconfig. Try

strSQL = "UPDATE tblconfig SET tblconfig.adn = True"

if you want to update *every single record* in tblConfig.
 
A

Afrosheen

I've got it working. Thanks for all your help. I have another question to
finish this problem.

The main goal was so if the tblconfig [adn] field was true then in the
second form 3 buttons would be disabled so only one button could be pushed.
If it was false then another set of buttons would be disabled.

The question is can I use a Case statement with this or should I use
something else and if so what and how?

Thanks again

Jeanette Cunningham said:
Assuming that there is ever only one record in tblconfig.
Is the field called adn or abn or adg or something else?
You must use the correct name for the field in the table.
In the code below, make sure you use the correct name for it.

Let's put in a debug.print to see what access finds as it goes through the
code.
Debug.Print gives you a record of what access found in the immediate window.
So open the form with the code below.
When access runs the lines that begin with Debug.Print, it prints the result
to the immediate window.
When the form errors, close the form and press Ctl + G to open the immediate
window.
If access found a value you will see something like
lookup: True

If access couldn't find a value for the lookup you will see
lookup:
Similarly for bolPrintA


Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
Debug.Print "lookup: " & DLookup("[adn]", "tblconfig")

bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

Debug.Print "bolPrintA: " & MsgBox bolPrintA
End Sub




Afrosheen said:
Update:
I need to check the tblconfig [adn] when the form first opens or loads.
When
ever I placed the code in the On open or On load event even with no code
both
will give me the error.

Thanks

Afrosheen said:
Hi John and Jeanette,
I've got the first part of the routine working where it will add the
check
mark in the checkbox. Now I'm working on the second part and I'm getting
an
error. I'm checking to see if the tblconfig [adb] is checked or not. Here
is
the code:

Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

MsgBox bolPrintA
End Sub

The error I'm getting is: Label not defined.

Thanks again
:

On Mon, 21 Jul 2008 17:26:00 -0700, Afrosheen

Hi Jeanette,
Here is what I entered:

Dim strSQL As String
strSQL = "UPDATE tblconfig '" & "SET tblconfig.adn = True"
CurrentDb.Execute strSQL, dbFailOnError

I just used the first part because all I need is the check box "abn"in
tblconfig checked. Then when I go to print our the report it will
check the
status of "abn" in tblconfig to see if its true or false. That's where
the
second part of the programming comes in.

You're inserting an extra quotemark. I'm guessing you got it from a
post explaining how to generate a criterion on a text field but you
certainly don't need a quotemark after tblconfig. Try

strSQL = "UPDATE tblconfig SET tblconfig.adn = True"

if you want to update *every single record* in tblConfig.
 
J

Jeanette Cunningham

You could do it easily without a case statement.

If bolPrintA = True then
me.cmdName1.enabled = true
me.cmdName2.enabled = true
me.cmdName3.enabled = true
me.cmdName4.enabled = false
me.cmdName5.enabled = false
me.cmdName6.enabled = false
else
'the reverse of the above
'you need to put the code here
End If

Notes: the above is probably easier to understand when you are reading your
code.
Replace the obvious with the names of your controls
In the form's property sheet, set the enabled property of those controls to
false.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Afrosheen said:
I've got it working. Thanks for all your help. I have another question to
finish this problem.

The main goal was so if the tblconfig [adn] field was true then in the
second form 3 buttons would be disabled so only one button could be
pushed.
If it was false then another set of buttons would be disabled.

The question is can I use a Case statement with this or should I use
something else and if so what and how?

Thanks again

Jeanette Cunningham said:
Assuming that there is ever only one record in tblconfig.
Is the field called adn or abn or adg or something else?
You must use the correct name for the field in the table.
In the code below, make sure you use the correct name for it.

Let's put in a debug.print to see what access finds as it goes through
the
code.
Debug.Print gives you a record of what access found in the immediate
window.
So open the form with the code below.
When access runs the lines that begin with Debug.Print, it prints the
result
to the immediate window.
When the form errors, close the form and press Ctl + G to open the
immediate
window.
If access found a value you will see something like
lookup: True

If access couldn't find a value for the lookup you will see
lookup:
Similarly for bolPrintA


Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
Debug.Print "lookup: " & DLookup("[adn]", "tblconfig")

bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

Debug.Print "bolPrintA: " & MsgBox bolPrintA
End Sub




Afrosheen said:
Update:
I need to check the tblconfig [adn] when the form first opens or loads.
When
ever I placed the code in the On open or On load event even with no
code
both
will give me the error.

Thanks

:

Hi John and Jeanette,
I've got the first part of the routine working where it will add the
check
mark in the checkbox. Now I'm working on the second part and I'm
getting
an
error. I'm checking to see if the tblconfig [adb] is checked or not.
Here
is
the code:

Private Sub Form_Open(Cancel As Integer)
Dim bolPrintA As Boolean
bolPrintA = Nz(DLookup("[adn]", "tblconfig"), False)

MsgBox bolPrintA
End Sub

The error I'm getting is: Label not defined.

Thanks again
:

On Mon, 21 Jul 2008 17:26:00 -0700, Afrosheen

Hi Jeanette,
Here is what I entered:

Dim strSQL As String
strSQL = "UPDATE tblconfig '" & "SET tblconfig.adn = True"
CurrentDb.Execute strSQL, dbFailOnError

I just used the first part because all I need is the check box
"abn"in
tblconfig checked. Then when I go to print our the report it will
check the
status of "abn" in tblconfig to see if its true or false. That's
where
the
second part of the programming comes in.

You're inserting an extra quotemark. I'm guessing you got it from a
post explaining how to generate a criterion on a text field but you
certainly don't need a quotemark after tblconfig. Try

strSQL = "UPDATE tblconfig SET tblconfig.adn = True"

if you want to update *every single record* in tblConfig.
 
A

Afrosheen

Thanks Jeanette for getting back to me so quickly.
I was just wondering about the case statement because I have 4 buttons I'm
working with. Will say they are 1, 2, 3, 4

In form one there are also 4 buttons. That's where the check mark is inserted.

So if tblconfig [adn] = true then in form two buttons 2, 3, 4 are disabled.
If tblconfig [adn] = false then 1, 3, 4 are disabled.

Then I have another check box in the tblconfig called [bdn]. It that = true
then 1, 2, 4 are diabled
If the tblconfig [bdn] = false then 1, 2, 3 are disabled.

That's the reason I was wondering about the case statement.
If the If Then Endif statement will work then fine. Not a problem

Thanks again.

Jeanette Cunningham said:
You could do it easily without a case statement.

If bolPrintA = True then
me.cmdName1.enabled = true
me.cmdName2.enabled = true
me.cmdName3.enabled = true
me.cmdName4.enabled = false
me.cmdName5.enabled = false
me.cmdName6.enabled = false
else
'the reverse of the above
'you need to put the code here
End If

Notes: the above is probably easier to understand when you are reading your
code.
Replace the obvious with the names of your controls
In the form's property sheet, set the enabled property of those controls to
false.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Afrosheen said:
I've got it working. Thanks for all your help. I have another question to
finish this problem.

The main goal was so if the tblconfig [adn] field was true then in the
second form 3 buttons would be disabled so only one button could be
pushed.
If it was false then another set of buttons would be disabled.

The question is can I use a Case statement with this or should I use
something else and if so what and how?

Thanks again

"Jeanette Cunningham" wrote:
 
A

Afrosheen

Update:
I found out because of the 4 buttons I was working with it was better to use
the Select Case statement. I just had to add another field to the tblconfig.

I did get it working the way I wanted. Thank you for all the help you've
given. I'm glad that there is a place to go to for help. If not then I
wouldn't be able to do what I've done so far.

Thanks again.


Afrosheen said:
Thanks Jeanette for getting back to me so quickly.
I was just wondering about the case statement because I have 4 buttons I'm
working with. Will say they are 1, 2, 3, 4

In form one there are also 4 buttons. That's where the check mark is inserted.

So if tblconfig [adn] = true then in form two buttons 2, 3, 4 are disabled.
If tblconfig [adn] = false then 1, 3, 4 are disabled.

Then I have another check box in the tblconfig called [bdn]. It that = true
then 1, 2, 4 are diabled
If the tblconfig [bdn] = false then 1, 2, 3 are disabled.

That's the reason I was wondering about the case statement.
If the If Then Endif statement will work then fine. Not a problem

Thanks again.

Jeanette Cunningham said:
You could do it easily without a case statement.

If bolPrintA = True then
me.cmdName1.enabled = true
me.cmdName2.enabled = true
me.cmdName3.enabled = true
me.cmdName4.enabled = false
me.cmdName5.enabled = false
me.cmdName6.enabled = false
else
'the reverse of the above
'you need to put the code here
End If

Notes: the above is probably easier to understand when you are reading your
code.
Replace the obvious with the names of your controls
In the form's property sheet, set the enabled property of those controls to
false.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Afrosheen said:
I've got it working. Thanks for all your help. I have another question to
finish this problem.

The main goal was so if the tblconfig [adn] field was true then in the
second form 3 buttons would be disabled so only one button could be
pushed.
If it was false then another set of buttons would be disabled.

The question is can I use a Case statement with this or should I use
something else and if so what and how?

Thanks again

"Jeanette Cunningham" wrote:
 
J

Jeanette Cunningham

Sure glad that we could help.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Afrosheen said:
Update:
I found out because of the 4 buttons I was working with it was better to
use
the Select Case statement. I just had to add another field to the
tblconfig.

I did get it working the way I wanted. Thank you for all the help you've
given. I'm glad that there is a place to go to for help. If not then I
wouldn't be able to do what I've done so far.

Thanks again.


Afrosheen said:
Thanks Jeanette for getting back to me so quickly.
I was just wondering about the case statement because I have 4 buttons
I'm
working with. Will say they are 1, 2, 3, 4

In form one there are also 4 buttons. That's where the check mark is
inserted.

So if tblconfig [adn] = true then in form two buttons 2, 3, 4 are
disabled.
If tblconfig [adn] = false then 1, 3, 4 are disabled.

Then I have another check box in the tblconfig called [bdn]. It that =
true
then 1, 2, 4 are diabled
If the tblconfig [bdn] = false then 1, 2, 3 are disabled.

That's the reason I was wondering about the case statement.
If the If Then Endif statement will work then fine. Not a problem

Thanks again.

Jeanette Cunningham said:
You could do it easily without a case statement.

If bolPrintA = True then
me.cmdName1.enabled = true
me.cmdName2.enabled = true
me.cmdName3.enabled = true
me.cmdName4.enabled = false
me.cmdName5.enabled = false
me.cmdName6.enabled = false
else
'the reverse of the above
'you need to put the code here
End If

Notes: the above is probably easier to understand when you are reading
your
code.
Replace the obvious with the names of your controls
In the form's property sheet, set the enabled property of those
controls to
false.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


I've got it working. Thanks for all your help. I have another
question to
finish this problem.

The main goal was so if the tblconfig [adn] field was true then in
the
second form 3 buttons would be disabled so only one button could be
pushed.
If it was false then another set of buttons would be disabled.

The question is can I use a Case statement with this or should I use
something else and if so what and how?

Thanks again

"Jeanette Cunningham" wrote:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Employee Shift Schedules 2
Looking up a looked up look up value! 1
filtering 2
24 hour time sheet 2
Real Data Formatting Challenge 3
1 report many headings 1
Database relationships--HELP 0
Save As 12

Top