If statement

  • Thread starter Marcelino via AccessMonster.com
  • Start date
M

Marcelino via AccessMonster.com

Hey good morning guys from Iraq. I doing a database for my soldiers and I
have a problem so far. I'm try to do a desicion. I want to check the rank
after select the soldier. to give me access to differents command buttons.
Like if the soldier is E-4 and below I don't need access to E-5 command
button. The code that I have is this one and when I executed unable access
to all the command group no matter therir rank.

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[SS] = '" & Me![Combo1] & "'"
SMName.Visible = True
if (rank="e1") or (rank="e2") or (rank="e3") or (rank="e4") then
NCOER.Enabled = false
Weapons.Enabled = True
OpenSchForm.Enabled = True
PromoForm.Enabled = false
VehForm.Enabled = True
end if

If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If somebody can help I'll be appreciate.
 
C

Chaim

Where does 'rank' come from? If it is coming from the recordset clone 'rs'
then you need to reference it like: rs.Fields("rank").value (or just
rs.Fields("rank")).

It also seems like you are mixing DAO and ADO object methods. Clone is an
ADO method; FindFirst is DAO.

You should also test the result of the FindFirst call, in case it comes back
empty. For example, you might want:

set rs = me.recordset.clone
rs.movefirst ' position at start of recordset
rs.find "[SS] = '" & Me![Combo1] & "'"
if rs.EOF = false then ' something was found because we're still in
recordset
<do the rest of your code>
end if

Good Luck!
 
M

Marcelino via AccessMonster.com

The field rank come from the same form that is not visible.
Where does 'rank' come from? If it is coming from the recordset clone 'rs'
then you need to reference it like: rs.Fields("rank").value (or just
rs.Fields("rank")).

It also seems like you are mixing DAO and ADO object methods. Clone is an
ADO method; FindFirst is DAO.

You should also test the result of the FindFirst call, in case it comes back
empty. For example, you might want:

set rs = me.recordset.clone
rs.movefirst ' position at start of recordset
rs.find "[SS] = '" & Me![Combo1] & "'"
if rs.EOF = false then ' something was found because we're still in
recordset
<do the rest of your code>
end if

Good Luck!
Hey good morning guys from Iraq. I doing a database for my soldiers and I
have a problem so far. I'm try to do a desicion. I want to check the rank
[quoted text clipped - 19 lines]
If somebody can help I'll be appreciate.
 
M

Marshall Barton

Marcelino said:
Hey good morning guys from Iraq. I doing a database for my soldiers and I
have a problem so far. I'm try to do a desicion. I want to check the rank
after select the soldier. to give me access to differents command buttons.
Like if the soldier is E-4 and below I don't need access to E-5 command
button. The code that I have is this one and when I executed unable access
to all the command group no matter therir rank.

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[SS] = '" & Me![Combo1] & "'"
SMName.Visible = True
if (rank="e1") or (rank="e2") or (rank="e3") or (rank="e4") then
NCOER.Enabled = false
Weapons.Enabled = True
OpenSchForm.Enabled = True
PromoForm.Enabled = false
VehForm.Enabled = True
end if

If Not rs.EOF Then Me.Bookmark = rs.Bookmark


You need to set the control's Enabled property one way or
the other, not just the case when the If is true.

Try something more like this:

Dim rs As DAO.Recordset
Dim bolE4 As Boolean

Set rs = Me.RecordsetClone
rs.FindFirst "[SS] = '" & Me![Combo1] & "'"
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
SMName.Visible = True
Set rs = Nothing
'---------------------------
bolE5 = (rank="e1") or (rank="e2") or (rank="e3") or
(rank="e4")
NCOER.Enabled = Not bolE4
Weapons.Enabled = bolE4
OpenSchForm.Enabled = bolE4
PromoForm.Enabled = Not bolE4
VehForm.Enabled = bolE4

You would probably be better off placing the code after the
line '-------- in the form's Current event so it can be used
to syncronize the controls when just navigate from one
record to another without using the combo box.
 
M

Marcelino via AccessMonster.com

It's working 50% because if I have an e5 or above then I don't have the NCOER
and Promo command button available this filter only is apllying to the e4 and
belows. Thanks for your help.

Marshall said:
Hey good morning guys from Iraq. I doing a database for my soldiers and I
have a problem so far. I'm try to do a desicion. I want to check the rank
[quoted text clipped - 17 lines]
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

You need to set the control's Enabled property one way or
the other, not just the case when the If is true.

Try something more like this:

Dim rs As DAO.Recordset
Dim bolE4 As Boolean

Set rs = Me.RecordsetClone
rs.FindFirst "[SS] = '" & Me![Combo1] & "'"
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
SMName.Visible = True
Set rs = Nothing
'---------------------------
bolE5 = (rank="e1") or (rank="e2") or (rank="e3") or
(rank="e4")
NCOER.Enabled = Not bolE4
Weapons.Enabled = bolE4
OpenSchForm.Enabled = bolE4
PromoForm.Enabled = Not bolE4
VehForm.Enabled = bolE4

You would probably be better off placing the code after the
line '-------- in the form's Current event so it can be used
to syncronize the controls when just navigate from one
record to another without using the combo box.
 
M

Marshall Barton

That's why I got rid of the If and used a boolean variable
instead.

Oops, I just noticed a typo, it should be:

bolE4 = (rank="e1") or (rank="e2") or (rank="e3") or
(rank="e4")

all on one line , of course.
--
Marsh
MVP [MS Access]

It's working 50% because if I have an e5 or above then I don't have the NCOER
and Promo command button available this filter only is apllying to the e4 and
belows. Thanks for your help.

Marshall said:
Hey good morning guys from Iraq. I doing a database for my soldiers and I
have a problem so far. I'm try to do a desicion. I want to check the rank
[quoted text clipped - 17 lines]
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

You need to set the control's Enabled property one way or
the other, not just the case when the If is true.

Try something more like this:

Dim rs As DAO.Recordset
Dim bolE4 As Boolean

Set rs = Me.RecordsetClone
rs.FindFirst "[SS] = '" & Me![Combo1] & "'"
If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark
SMName.Visible = True
Set rs = Nothing
'---------------------------
bolE5 = (rank="e1") or (rank="e2") or (rank="e3") or
(rank="e4")
NCOER.Enabled = Not bolE4
Weapons.Enabled = bolE4
OpenSchForm.Enabled = bolE4
PromoForm.Enabled = Not bolE4
VehForm.Enabled = bolE4

You would probably be better off placing the code after the
line '-------- in the form's Current event so it can be used
to syncronize the controls when just navigate from one
record to another without using the combo box.
 

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

Load event - multiple criteria 0
OnLoad event criteria 7
Search combo box 2
Error 2147352567 2
RunTime Error 3070 11
Error 2237 8
Combo Box Value 1
VBA for NotInList return to old record or BeforeUpdate value 2

Top