PC Review


Reply
Thread Tools Rate Thread

Easy one...referring to a table

 
 
AngiW
Guest
Posts: n/a
 
      2nd Feb 2004
I have 2 tables. Employee Main and Accruals Used. When they select an
employee on the Accruals used form (uses Accruals used table), I want to see if
that employee is eligible to take time (some aren't). I was trying to use an
IF statement, but I can't get it to work since the info that I need to refer to
is in the Employee Main table. I thought it was like table![employee
main]...etc, but that doesn't work either. TIA! Here's the code I tried:

Private Sub EmployeeID_LostFocus()

Dim Msg1, Msg2, Style, Title, Response
Msg1 = "Employee is part time. Not eligible."
Msg2 = "Employee is a casual. Not eligible."
Style = vbOK + vbExclamation
Title = "Error"

If [employee main].Status = "Part time" Then
Response = MsgBox(Msg1, Style, Title)
Else
If [employee main].Status = "casual" Then
Response = MsgBox(Msg2, Style, Title)
End If
End If

End Sub

 
Reply With Quote
 
 
 
 
John Spencer (MVP)
Guest
Posts: n/a
 
      2nd Feb 2004
If you don't have the field available in the form's recordsource then you can
use the DLookup function.

Select Case DLookup("Status","[Employee Main]", _
"EmployeeID=" & Chr(34) & Me.EmployeeID & Chr(34))
Case "Part Time"
MsgBox ...
Case "Casual"
MsgBox ...
End Select

If your EmployeeID (or whatever your primary key is for Employee Main) is not
text but numeric then remove the & Chr(34) from the DLookup.


AngiW wrote:
>
> I have 2 tables. Employee Main and Accruals Used. When they select an
> employee on the Accruals used form (uses Accruals used table), I want to see if
> that employee is eligible to take time (some aren't). I was trying to use an
> IF statement, but I can't get it to work since the info that I need to refer to
> is in the Employee Main table. I thought it was like table![employee
> main]...etc, but that doesn't work either. TIA! Here's the code I tried:
>
> Private Sub EmployeeID_LostFocus()
>
> Dim Msg1, Msg2, Style, Title, Response
> Msg1 = "Employee is part time. Not eligible."
> Msg2 = "Employee is a casual. Not eligible."
> Style = vbOK + vbExclamation
> Title = "Error"
>
> If [employee main].Status = "Part time" Then
> Response = MsgBox(Msg1, Style, Title)
> Else
> If [employee main].Status = "casual" Then
> Response = MsgBox(Msg2, Style, Title)
> End If
> End If
>
> End Sub

 
Reply With Quote
 
AngiW
Guest
Posts: n/a
 
      2nd Feb 2004
John,
Thank you for that...I forgot how to do cases. But it's not working. It lets
me add the record even if they're part time and a message box never comes up.
EmployeeID is a number field. Primary key for Employee table is Employee ID.
Foreign key is EmployeeID. Does the fact that I'm using a lookup on the
foreign key to display their name (last name + first name) instead of their
number change anything? I looked and it's storing their name instead of their
number in the table, which is what I didn't want, but that's what it's doing.
I have the bound column set to the number, not the name. Here's what I now
have. What am I doing wrong?? So much for me thinking this was easy!

Select Case DLookup("[Status]", "Employee Main", _
"[Employee ID] = Me.EmployeeID")
Case "Part Time"
Response = MsgBox(Msg1, Style, Title)
Case "Casual"
Response = MsgBox(Msg2, Style, Title)
End Select

 
Reply With Quote
 
John Spencer (MVP)
Guest
Posts: n/a
 
      3rd Feb 2004
You need to remove Me.EmployeeID from the quotes, so that you have a value being
put into the criteria string.

Select Case DLookup("[Status]", "Employee Main", _
"[Employee ID] =" & Me.EmployeeID)
Case "Part Time"
Response = MsgBox(Msg1, Style, Title)
Case "Casual"
Response = MsgBox(Msg2, Style, Title)
End Select


AngiW wrote:
>
> John,
> Thank you for that...I forgot how to do cases. But it's not working. It lets
> me add the record even if they're part time and a message box never comes up.
> EmployeeID is a number field. Primary key for Employee table is Employee ID.
> Foreign key is EmployeeID. Does the fact that I'm using a lookup on the
> foreign key to display their name (last name + first name) instead of their
> number change anything? I looked and it's storing their name instead of their
> number in the table, which is what I didn't want, but that's what it's doing.
> I have the bound column set to the number, not the name. Here's what I now
> have. What am I doing wrong?? So much for me thinking this was easy!
>
> Select Case DLookup("[Status]", "Employee Main", _
> "[Employee ID] = Me.EmployeeID")
> Case "Part Time"
> Response = MsgBox(Msg1, Style, Title)
> Case "Casual"
> Response = MsgBox(Msg2, Style, Title)
> End Select

 
Reply With Quote
 
AngiW
Guest
Posts: n/a
 
      3rd Feb 2004
Thank you...that was it!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referring to a table by group name kitkat Microsoft Powerpoint 0 8th Jul 2008 04:33 PM
Referring to a table on any slide? Lily Microsoft Powerpoint 1 8th May 2008 08:50 PM
Referring to another field in the same table =?Utf-8?B?TWFyaWFubmU=?= Microsoft Access 2 24th Jul 2006 05:47 PM
Easy Syntax question: referring to worksheet by VBA name KR Microsoft Excel Programming 3 23rd Nov 2004 12:06 AM
Row source of table referring to same table? Noozer Microsoft Access Queries 2 12th Aug 2004 09:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 PM.