Senin, 01 Agustus 2016

Re: [MS_AccessPros] Replace field if another exists.

 

John,

I found that I had set the default value of person_ID in tblCitation to 0. I removed that and now its working correctly. 

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070

"Anyone who claimed that old age had brought them patience was either lying or senile."  







From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: MS_Access_Professionals@yahoogroups.com
Sent: Sunday, July 31, 2016 4:08 PM
Subject: Re: [MS_AccessPros] Replace field if another exists.

 
Yes.  0 is not the same as Null.  You need:

IIf(IsNull([PersonID]) Or ([PersonID] = 0), ...

John

Sent from my iPhone

On Jul 31, 2016, at 5:39 PM, Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

I guess I was not quite done. When I run the query it pulls in the person name from the tbl_persons table, but if there is no personId (PersonID = 0), then it should be pulling the name from the tbl_Citation but for some reason it is not seeing even though there is an entry there.

SELECT tbl_citations.CitationID, tbl_citations.FirstName, tbl_citations.MiddleName, tbl_citations.LastName, tbl_citations.IsLicensed, tbl_citations.Person_ID, tbl_citations.Fee, tbl_citations.ViolationCodeID, tbl_citations.WardenID, tbl_citations.CourtDateTime, tbl_citations.ReasonForViolation, tbl_citations.Priority, tbl_citations.OpenDate, tbl_citations.Close, tbl_citations.Comments, tbl_citations.Created_By, tbl_citations.Created_On, tbl_citations.Edited_By, tbl_citations.Edited_On, IIf(IsNull([Person_ID]),[FirstName] & " " & [LastName],DLookUp("cPersonName","qryAdd_People","Person_ID = " & [Person_ID])) AS PersonName, tbl_lkpViolationCode.Code, DLookUp("WardenName","qryLookup_WardenName","WardenID = " & [WardenID]) AS WardenName
FROM tbl_citations LEFT JOIN tbl_lkpViolationCode ON tbl_citations.ViolationCodeID = tbl_lkpViolationCode.ViolationCodeID;

Is it the case that PersonID contains a 0 and is not truly NUll? 

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070

"Anyone who claimed that old age had brought them patience was either lying or senile."  







From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: MS_Access_Professionals@yahoogroups.com
Sent: Friday, July 29, 2016 2:54 PM
Subject: Re: [MS_AccessPros] Replace field if another exists.

 
Art-

Sorry, I didn't notice the extra ( in your original syntax.  Try:

IIf(IsNull(PersonID]), [FirstName] & " " & [LastName], DLookup("LastName", "tbl_Persons", "PersonID = " & [PersonID]))

John Viescas, author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Access Applications

On Jul 29, 2016, at 15:00, Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

THis is what I have got so far:

SELECT tbl_citations.CitationID, tbl_citations.FirstName, tbl_citations.MiddleName, tbl_citations.LastName, tbl_citations.IsLicensed, tbl_citations.Person_ID, tbl_citations.Fee, tbl_citations.ViolationCodeID, tbl_citations.OfficerID, tbl_citations.CourtDateTime, tbl_citations.ReasonForViolation, tbl_citations.Priority, tbl_citations.OpenDate, tbl_citations.Close, tbl_citations.Comments, tbl_citations.Created_By, tbl_citations.Created_On, tbl_citations.Edited_By, tbl_citations.Edited_On, [FirstName] & " " & [LastName] AS FullName, IIf(IsNull((PersonID]), [FirstName] & " " & [LastName], DLookup("LastName", "tbl_Persons", "PersonID = " & [PersonID]))
FROM tbl_citations;

I am receiving a syntax error in the following line:

IIf(IsNull((PersonID]), [FirstName] & " " & [LastName], DLookup("LastName", "tbl_Persons", "PersonID = " & [PersonID]))
FROM tbl_citations;
 

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070

"Anyone who claimed that old age had brought them patience was either lying or senile."  







From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: MS_Access_Professionals@yahoogroups.com
Sent: Friday, July 29, 2016 12:39 PM
Subject: Re: [MS_AccessPros] Replace field if another exists.

 
Art-

If this expression is in the underlying query, then don't refer to the form control.  Do this:

IIf(IsNull((PersonID]), [FirstName] & " " & [LastName], DLookup("PersonName", "tblPerson", "PersonID = " & [PersonID]))

John Viescas, author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Access Applications

On Jul 29, 2016, at 14:15, Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

OK. I knew I was missing something. THis query will be used on a continuous form where the combobox does not exist.

IIf(IsNull((PersonID]), [FirstName] & " " & [LastName], DLookup("PersonName", "tblPerson", "PersonID = " & [Forms]![Myform]![cmbPersonID]))
 
Something like this maybe.

Here is the structure of the tblCitation that this query is derived from:

SELECT tbl_citations.CitationID, tbl_citations.FirstName, tbl_citations.MiddleName, tbl_citations.LastName, tbl_citations.IsLicensed, tbl_citations.Person_ID, tbl_citations.Fee, tbl_citations.ViolationCodeID, tbl_citations.OfficerID, tbl_citations.CourtDateTime, tbl_citations.ReasonForViolation, tbl_citations.Priority, tbl_citations.OpenDate, tbl_citations.Close, tbl_citations.Comments, tbl_citations.Created_By, tbl_citations.Created_On, tbl_citations.Edited_By, tbl_citations.Edited_On
FROM tbl_citations;

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070

"Anyone who claimed that old age had brought them patience was either lying or senile."  







From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: MS_Access_Professionals@yahoogroups.com
Sent: Thursday, July 28, 2016 6:52 PM
Subject: Re: [MS_AccessPros] Replace field if another exists.

 
Art-

Yup.  But it sounds like you need something like:

IIf(IsNull([Forms]![Myform]![cmbPersonID]), [FirstName] & " " & [LastName], DLookup("PersonName", "OtherTable", "PersonID = " & [Forms]![Myform]![cmbPersonID]))

John Viescas, author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Access Applications

On Jul 28, 2016, at 18:23, Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Here is example of what you are talking about I have in another application:

SELECT [Learning Center Non Client Activities].NonClientActivityID, [Learning Center Non Client Activities].LearningCenterID, [Learning Center Non Client Activities].ActivityDate, IIf(IsNull([ProgramName]),[LastName] & ", " & [FirstName],[ProgramName]) AS [Non-ClientName], [Learning Center Non Client Activities].Note, [Lookup Learning Center Client Activity Type].ClientActivityDetailName, [Learning Center Non Client Activities].ActivityTypeID
FROM [Learning Center Non Client Activities] INNER JOIN [Lookup Learning Center Client Activity Type] ON [Learning Center Non Client Activities].ActivityTypeID=[Lookup Learning Center Client Activity Type].ClientActivityDetailID;

 IIf(IsNull([ProgramName]),[LastName] & ", " & [FirstName],[ProgramName]) AS [Non-ClientName

But in my new case, Instead of ProgramName I have PersonID, BUt I need to use the DLOOKUP to pull the person name out of tblPerson based on the PersonID selected.

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070

"Anyone who claimed that old age had brought them patience was either lying or senile."  







From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: MS_Access_Professionals@yahoogroups.com
Sent: Thursday, July 28, 2016 2:26 PM
Subject: Re: [MS_AccessPros] Replace field if another exists.

 
Art-

Sounds like you need an IIf function that tests the selection in the combo box and returns either the concatenated name or a DLookup to the other table.  Without more info, I can't give you specific code.

John Viescas, author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Access Applications

On Jul 28, 2016, at 16:11, dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

I have a query in which I need to display either the concatenated fullname or a name based on a ID in another table.

Select [FirstName] & " " & [LastName] as FullName, (or associated name from tblPerson if PersonID is selected, CitationID, Code, CitiationDate
FROM tblCitation

I would need to pull the [FirstName] & " " & [LastName] from tblPerson If the user selects a PersonID from the dropdown.

Clear as mud  know

Thank you,
Art Lorenzini
Sioux Falls, SD










__._,_.___

Posted by: Art Lorenzini <dbalorenzini@yahoo.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (12)

Save time and get your email on the go with the Yahoo Mail app
Get the beautifully designed, lighting fast, and easy-to-use Yahoo Mail today. Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar