PC Review Forums Newsgroups Microsoft Access Microsoft Access VBA Modules Compare with table values

Reply

Compare with table values

 
Thread Tools Rate Thread
Old 15-04-2004, 09:51 PM   #1
=?Utf-8?B?RGFuaWVsIFA=?=
Guest
 
Posts: n/a
Default Compare with table values


Hello

I have a table with a field ("Name"). I would like to compare the CurrentUser() against all of the values in the "Name" column. How can I do this

Basically I would like to create something along the lines of
if currentUser() <> ................... the

Daniel
  Reply With Quote
Old 16-04-2004, 02:37 AM   #2
John Spencer (MVP)
Guest
 
Posts: n/a
Default Re: Compare with table values

Perhaps you can use the Domain functions.

I would probably use the DCount function in this case.

If DCount("*","TableName","[Name]=""" & CurrentUser() & """") = 0 Then
'Not there so do something
Else
'At least one match, so do something else
End If

Daniel P wrote:
>
> Hello,
>
> I have a table with a field ("Name"). I would like to compare the CurrentUser() against all of the values in the "Name" column. How can I do this?
>
> Basically I would like to create something along the lines of:
> if currentUser() <> ................... then
>
> Daniel

  Reply With Quote
Old 16-04-2004, 03:01 PM   #3
=?Utf-8?B?RGFuaWVsIFA=?=
Guest
 
Posts: n/a
Default Re: Compare with table values

John,

I tried to implement your code for my specific case and I can't seem to get it to work. In my case the [Name] column contains the frist name followed by the last name of each individual for the comparison purpose I need to transform it so that I compare the currentuser() with the first letter of the first name followed by the last name.

Example
Name column contains Julian Pare but for the comparison I need jpare to be compared with the current user.

I transformed your code as shown below:
If DCount("*", "Stress Tbl", "left([Name],1)" & "Right([Name], len([Name])-Instr(1, [Name], " "))=""" & CurrentUser() & """") = 0 Then
but can't get it to work.

Any help is appreciated.

Daniel
  Reply With Quote
Old 16-04-2004, 03:11 PM   #4
=?Utf-8?B?RGFuaWVsIFA=?=
Guest
 
Posts: n/a
Default Re: Compare with table values

John

I fixed one issue with the following mod to your original code

If DCount("*", "Stress Tbl", Left([Name], 1) & Right([Name], Len([Name]) - InStr(1, [Name], " ")) & "=" & CurrentUser() & "") = 0 The

but when it gets run the [Name] value is not that of the names in my table but rather the name of the subform form where the event occurs?! I'm confused the second section of the DCount function clearly states to use the "Stress Tbl"...

Any Ideas

Daniel
  Reply With Quote
Old 18-04-2004, 12:46 AM   #5
John Spencer (MVP)
Guest
 
Posts: n/a
Default Re: Compare with table values

Well, now you know why it is a bad idea to use NAME as the name of anything in
Access. Every object has a name property. You must disambiguate what you are
referring to. Also, in your case you need the field name in the table.

PERHAPS the following might work, but I'm not sure you can use VBA functions
inside a DCount function

If DCount("*", "Stress Tbl",
"Left([Name], 1) & Right([Name], Len([Name]) - InStr(1, [Name], "" "")) =" &
Chr(34) & CurrentUser() & Chr(34)) = 0 Then

Try it. If that still doesn't work, post back again.


Daniel P wrote:
>
> John,
>
> I fixed one issue with the following mod to your original code:
>
> If DCount("*", "Stress Tbl", Left([Name], 1) & Right([Name], Len([Name]) - InStr(1, [Name], " ")) & "=" & CurrentUser() & "") = 0 Then
>
> but when it gets run the [Name] value is not that of the names in my table but rather the name of the subform form where the event occurs?! I'm confused the second section of the DCount function clearly states to use the "Stress Tbl"....
>
> Any Ideas?
>
> Daniel

  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off