Add Narrative Based on Other Field Values (1 Viewer)

alisonfinfrock

New member
Local time
Yesterday, 19:42
Joined
Apr 13, 2015
Messages
4
Hi All! I’ve been a reader on here for a while (thanks to your helpful answers always popping up in my Google searches) but finally have a post-worthy issue of my own that has prompted me to join your ranks. Just wanted to start off by saying thanks for being so helpful in the past! I wasn't sure if I should post this in Tables or Forms, so my apologies if I put it in the wrong place!



I have a database (native, Access 2013 .accdb) that tracks call activity for marketing purposes. There are fields in the table for contact info as well as fields for other information we are required to gather during the call. These fields are primarily dropdown combo-box fields, number fields, or date fields. Our staff records the proper responses to each field in the call log/record. We also have a field called “Notes” that is a Long Text (formerly “Memo”) type field. This field gets populated with a brief narrative of the call. I understand the dangers inherent in using this field type (complications, corruptions, etc.), but due to some reporting requirements we don’t have much other choice but to use it and we need this narrative to be saved in the table with the rest of the call record.



Just a slight backtrack to better understand our environment, our database is set up with a back end/front end type setup. The staff uses forms tied to queries to pull the information they need from our table, and do all their data entry for the calls onto those forms. They do not ever access the table itself without going through a query. They also don’t do anything in “datasheet” view; all their access is through a few controlled forms.



Now for the issue: I am trying to auto-populate some or all of the narrative needed in the Notes field, based on the responses in other fields. This reduces our employee’s need to type out the info again, both wasting time and potentially causing errors in the narrative (which would then take more time to be fixed later on by our quality team). Just so you can get a feel for what I mean by the narrative, it goes something like this: “An appointment has been set for [Appt Date] at [Appt Time] to discuss gas conversion. They are currently using a [Heating System Type] system that is [Heating System Age] years old. They use [Heating System Fuel] for heat now.” Etc. The write-up is a bit longer, but I think you can get the point from this. The bracketed parts are the values from fields of those names on the call record.



I have had success doing this on past databases by using the following code (as an OnClick property for a button on my form): Forms![All Records Frm]!Notes = Eval("""An appointment has been set for "" & [Appt Date] & "" between "" & [Appt Time] & "" with "" & Forms![All Records Frm]![F Name] {truncated here, since I think you get the point}


I am trying to get this to work on a new database, and I’m not having the same luck. Does anyone know if there is a size/length limit to using this particular method? (It seems the code in VBA for this write-up is getting cut off and moving down to the next line, and that is where my problem lies.) Is there another (better, faster, smarter) way to accomplish what I need to accomplish instead of using the “Eval” that I’m using now? (That wouldn’t surprise me. I’m more or less self-taught, internet-taught, and “For Dummies”-taught in Access…)


Thank you for your time and assistance!
Alison
:banghead::confused:
 

bob fitz

AWF VIP
Local time
Today, 00:42
Joined
May 23, 2011
Messages
4,719
Can you tell us a bit more about what actually happens when the code is run and what results you get
 

alisonfinfrock

New member
Local time
Yesterday, 19:42
Joined
Apr 13, 2015
Messages
4
Hi Bob! When I try to run it, I get a "Compile Error: Syntax Error". I have checked the syntax of the full code and have not found any issues other than the fact that it is split down to a second line rather than just being on the same line (as all my other, shorter ones were). It seems if I cut about a third of it out and run the same code, it runs just fine. Unfortunately, I need the full writeup; I can't really afford to leave out some of it.
 

bob fitz

AWF VIP
Local time
Today, 00:42
Joined
May 23, 2011
Messages
4,719
Can you copy (cut and paste) the short code that works and the longer code that does not work. Please use the code tags.
 

alisonfinfrock

New member
Local time
Yesterday, 19:42
Joined
Apr 13, 2015
Messages
4
Sorry, I'm new enough not to be sure what you mean by "code tags", so let me know if this isn't what you meant.
Code that doesn't work:
Private Sub Command114_Click()
Forms![All Records Frm]!Notes = Eval("""An appointment has been set for "" & Forms![All Records Frm]![Appt Date] & "" between "" & Forms![All Records Frm]![Appt Time] & "" with "" & [Forms]![All Records Frm]![F Name] & "" "" & [Forms]![All Records Frm]![L Name] & "", "" & [Forms]![All Records Frm]![Title] & "". They are interested in discussing energy efficiency upgrades at this facility, which they "" & Forms![All Records Frm]![Rent or Own?] & "". Approximate square footage: "" & Forms![All Records Frm]![Approx Sq Ft] & "". The ceiling height is "" & Forms![All Records Frm]![Approx Ceiling Height] & "". They are open for business "" & Forms![All Records Frm]![Days of Operation] & "" and they have been in business for "" & Forms![All Records Frm]![Years in Business] & ""years. They receive electric service from "" & Forms![All Records Frm]![Electric Company] & "" and gas service from "" & Forms![All Records Frm]![Gas Company] & "". They currently use "" & Forms![All Records Frm]![Heating Fuel] & "" to heat, with a ""& Forms![All Records Frm]![Heating System Type] & "" system that is "" & Forms![All Records Frm]![Heating System Age] & "" years old. Their thermostat is "" & Forms![All Records Frm]![Thermostat Type] & "". Their HVAC system is a "" & Forms![All Records Frm]![HVAC Type] & "" unit that is "" & Forms![All Records Frm]![HVAC Age] & "" years old. Their lighting is as follows: T12-"" & Forms![All Records Frm]![Have T12 Bulbs?] & "", T8-"" & Forms![All Records Frm]![Have T8 Bulbs?] & "", Sodium Bulbs-"" & Forms![All Records Frm]![Have Sodium Bulbs?] & "", Other Bulbs-"" & Forms![All Records Frm]![Have Other Bulbs?] & "" "" & Forms![All Records Frm]![Other Bulbs]")
End Sub

Code that works:
Private Sub Command114_Click()
Forms![All Records Frm]!Notes = Eval("""An appointment has been set for "" & Forms![All Records Frm]![Appt Date] & "" between "" & Forms![All Records Frm]![Appt Time] & "" with "" & [Forms]![All Records Frm]![F Name] & "" "" & [Forms]![All Records Frm]![L Name] & "", "" & [Forms]![All Records Frm]![Title] & "". They are interested in discussing energy efficiency upgrades at this facility, which they "" & Forms![All Records Frm]![Rent or Own?] & "". Approximate square footage: "" & Forms![All Records Frm]![Approx Sq Ft] & "". The ceiling height is "" & Forms![All Records Frm]![Approx Ceiling Height] & "". They are open for business "" & Forms![All Records Frm]![Days of Operation] & "" and they have been in business for "" & Forms![All Records Frm]![Years in Business] & ""years. They receive electric service from "" & Forms![All Records Frm]![Electric Company] & "" and gas service from "" & Forms![All Records Frm]![Gas Company] & "". They currently use "" & Forms![All Records Frm]![Heating Fuel]")
End Sub

It cuts off the line break shortly after this spot. (Cut off occurs here
[Heating Fuel] & "" to heat, with a ""& Forms![All Records Frm]![Heating System Type] after the comma.)
 

bob fitz

AWF VIP
Local time
Today, 00:42
Joined
May 23, 2011
Messages
4,719
Can you just try the full code without the comma after the word heat
 

alisonfinfrock

New member
Local time
Yesterday, 19:42
Joined
Apr 13, 2015
Messages
4
I get the same error as before without the comma after the word heat. Additionally, the line break/cutoff occurs in the same spot as well.
 

bob fitz

AWF VIP
Local time
Today, 00:42
Joined
May 23, 2011
Messages
4,719
Can you post a copy of the db for me to play with tomorrow while I'm off work.
 

Users who are viewing this thread

Top Bottom