473,594 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating Memo Field from Combo Box

tdw
206 New Member
Hi all,

I have tried a few different methods to accomplish this, but with no luck. I will post the code for the latest attempt at the end of this post.

I work at a land surveying company. This database is for tracking survey orders.
One of the fields is for entering the Subdivision that the parcel of land is in. That field on the New Orders entry form is called "SUB_NAME". On that form it is a combo box that uses a seperate table called "subd". In that table are two fields only: "subd_name" (not to be confused with "SUB_NAME" in the form) and "warn_messa ge". The purpose for "warn_messa ge" is because some subdivisions have special notes or instructions for the field crew conducting the survey, relevant to that particular subdivision (such as "Note: The only access to back yards is through the houses", "Note: None of the lots in this subdivision are staked", etc.)

On my New Orders form I have a Memo field for special instructions or comments called "COMM_1". This memo field serves a variety of purposes, including special instructions for the field crew.

What I am trying to do is as follows:
When a subdivision is selected or typed into the "SUB_NAME" field, I want the code to look to see if a warning message exists for that subdivision on the "subd" table. If one does, I want it to pop up a message box displaying that warning message. I want the person entering the records to have the option (via the yes/no message box) to automatically enter that warning message in the the "COMM_1" memo field. Now, there may already be something in that memo field, and I don't want the new warning message to replace whatever already exists there. I just want it inserted before the existing text.

So far, some of my various attempts work fine for the message box, but will not insert the warning message text into the memo field. My latest attempt neither displays the warning message in the message box, nor inserts it into the memo field. My combo box has two columns: one for "subd_name" and the second for "warn_messa ge". The second column is hidden (width = 0 in)

What am I doing wrong?

Expand|Select|Wrap|Line Numbers
  1. Private Sub SUB_NAME_AfterUpdate()
  2.  
  3. '   Check to see if this subdivision is already in the subdivisions table
  4.     If DCount("*", "subd", "[subd_name]='" & Me!SUB_NAME & "'") = 0 Then
  5.     '   Yes No Box
  6.         Dim Msg, Style, Title, Response
  7.         Msg = "This Subdivision is not in the list. Do you want to add it?"    ' Define message.
  8.         Style = vbYesNo   ' Define buttons.
  9.         Title = "Add Subdivision"    ' Define title.
  10.         Response = MsgBox(Msg, Style, Title)
  11.             If Response = vbYes Then    ' User chose Yes
  12.                 DoCmd.RunMacro "Open Subdivisions Form"
  13.             End If
  14.  
  15.     Else
  16.         If DLookup("[warn_message]", "subd", "[subd_name] = '" _
  17.                 & Me.SUB_NAME & "'") <> 0 Then
  18.  
  19.             Dim stWarn As String
  20.             stWarn = Me.SUB_NAME.Column(2)
  21.  
  22.         '   Yes No Box
  23.             Msg = stWarn & Chr(13) & "Do you want to add this message into the comments for this order?"    ' Define message.
  24.             Style = vbYesNo   ' Define buttons.
  25.             Title = "Warning"    ' Define title.
  26.             Response = MsgBox(Msg, Style, Title)
  27.                 If Response = vbYes Then    ' User chose Yes
  28.                     Dim stComments As String
  29.                     stComments = Me.COMM_1
  30.                     Me.COMM_1 = stWarn & Chr(13) & stComments
  31.                 End If
  32.         End If
  33.  
  34.     End If
  35. End Sub
  36.  
Again, to help avoid confusion:
"SUB_NAME" is the field in the main table and in the form for entering the subdivision.
"subd_name" is the field on the subdivisions table ("subd") that the combo box looks up.

Thanks
Nov 11 '08 #1
11 3718
puppydogbuddy
1,923 Recognized Expert Top Contributor
Try this with the corrections (corrected code lines are noted as such) . I am not certain about this, but you may also have to change the width of the [warn_message] column (bound) in the combobox to .1 (point one tenth of an inch) which will be enough to keep it hidden, yet make its value accessible for passing to the textbox. I seem to remember that the column width can't be zero if you intend to copy and pass the value of the column,

Expand|Select|Wrap|Line Numbers
  1. Private Sub SUB_NAME_AfterUpdate() 
  2.  
  3. '   Check to see if this subdivision is already in the subdivisions table 
  4.     If DCount("*", "subd", "[subd_name]='" & Me!SUB_NAME & "'") = 0 Then 
  5.     '   Yes No Box 
  6.         Dim Msg, Style, Title, Response 
  7.         Msg = "This Subdivision is not in the list. Do you want to add it?"    ' Define message. 
  8.         Style = vbYesNo   ' Define buttons. 
  9.         Title = "Add Subdivision"    ' Define title. 
  10.         Response = MsgBox(Msg, Style, Title) 
  11.             If Response = vbYes Then    ' User chose Yes 
  12.                 DoCmd.RunMacro "Open Subdivisions Form" 
  13.             End If 
  14.  
  15.     Else 
  16.         If DCount("[warn_message]", "subd", "[subd_name] = '" _   '<<<correction
  17.                 & Me.SUB_NAME & "'") > 0 Then 
  18.  
  19.             Dim stWarn As String 
  20.             stWarn = Me.subd_name.Column(2).Value    '<<<<<correction>> 
  21.  
  22.         '   Yes No Box 
  23.             Msg = stWarn & Chr(13) & "Do you want to add this message into the comments for this order?"    ' Define message. 
  24.             Style = vbYesNo   ' Define buttons. 
  25.             Title = "Warning"    ' Define title. 
  26.             Response = MsgBox(Msg, Style, Title) 
  27.                 If Response = vbYes Then    ' User chose Yes 
  28.                     Dim stComments As String 
  29.                     stComments = Me.COMM_1 
  30.                     Me.COMM_1 = stWarn & Chr(13) & stComments 
  31.                 End If 
  32.         End If 
  33.  
  34.     End If 
  35. End Sub 
Nov 11 '08 #2
tdw
206 New Member
those corrections made sense to me, however nothing seems to have changed.
Nov 11 '08 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
1. Did you try changing the width of the bound column of the combobox from zero to .1, as suggested?
2. Did your test data have a warning message?
3. You need to place control breaks and look at the values of your variables at the breakpoints. Which variables do not show any values where there should be values?
Nov 11 '08 #4
tdw
206 New Member
I have column 2 of the combo box set at 0.1". Strangely, the combo box has a horizontal scroll bar at the bottom when open, and if I scroll right the second column appears and most of the warning message is shown. That doesn't seem to me like it's only 0.1".

I am not very good at figuring out the watches and breakpoints. I don't know if I'm doing them right. What I did is selected both lines that are supposed to give a value to the strings (stWarn and stComments). For each line I selected "Add Watch" from the Debug menu. I told it to break when value changes. Then I went back to my form and typed in a subdivision that I know has a warning message. When nothing happened, I rewrote a little bit of the code. I also tried "Toggle Breakpoint" and that didn't seem to do anything different.

After the slight rewrite the yes/no msgbox part works. It does display the box with the warning message in it. But if I click yes, it does nothing. Going back to look at the watch window, all it has are two lines (one for each expression). On both lines the Value column says "<out of context>" and the Type column says "empty".

I must not be doing it right, because obviously stWarn DID have the value of the warning message because it displayed it in the yes/no box.

Here is how my code looks right now:
Expand|Select|Wrap|Line Numbers
  1. Private Sub SUB_NAME_AfterUpdate()
  2.  
  3. Dim stWarn As String
  4. Dim stComments As String
  5.  
  6. '   Check to see if this subdivision is already in the subdivisions table
  7.     If DCount("*", "subd", "[subd_name]='" & Me!SUB_NAME & "'") = 0 Then
  8.     '   Yes No Box
  9.         Dim Msg, Style, Title, Response
  10.         Msg = "This Subdivision is not in the list. Do you want to add it?"    ' Define message.
  11.         Style = vbYesNo   ' Define buttons.
  12.         Title = "Add Subdivision"    ' Define title.
  13.         Response = MsgBox(Msg, Style, Title)
  14.             If Response = vbYes Then    ' User chose Yes
  15.                 DoCmd.RunMacro "Open Subdivisions Form"
  16.             End If
  17.  
  18.     Else
  19.         If DCount("[warn_message]", "subd", "[subd_name] = '" _
  20.                  & Me.SUB_NAME & "'") > 0 Then
  21.  
  22.             stWarn = DLookup("[warn_message]", "subd", "[subd_name] = '" _
  23.                  & Me.SUB_NAME & "'")
  24.  
  25.         '   Yes No Box
  26.             Msg = stWarn & Chr(13) & "Do you want to add this message into the comments for this order?"    ' Define message.
  27.             Style = vbYesNo   ' Define buttons.
  28.             Title = "Warning"    ' Define title.
  29.             Response = MsgBox(Msg, Style, Title)
  30.                 If Response = vbYes Then    ' User chose Yes
  31.                     stComments = Me.COMM_1
  32.                     Me.COMM_1 = stWarn & Chr(13) & stComments
  33.                 End If
  34.         End If
  35.  
Nov 12 '08 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
I think because you have a memo field involved, you have to trim trailing and leading spaces when copying.
Expand|Select|Wrap|Line Numbers
  1. 'Try changing lines 30 thru 33:
  2.             If Response = vbYes Then    ' User chose Yes 
  3.                     stComments = Me.COMM_1 
  4.                     Me.COMM_1 = stWarn & Chr(13) & stComments 
  5.             End If
  6.  
  7. 'To this:
  8.             If Response = vbYes Then    ' User chose Yes 
  9.                    stComments = Trim(Me.COMM_1)
  10.                    Me.COMM_1 = stWarn & Chr(13) & stComments 
  11.             End If
Nov 12 '08 #6
tdw
206 New Member
Unfortunately it didn't work. I also tried just modifying it altogether so that it was just being told to to make COMM_1 equal the warning message without worrying about including the existing data in COMM_1. Still nothing.
So then I tried changing the COMM_1 in both lines to a different "text" field to see if it was a memo field problem, using only stWarn and not stComments. That worked. So then I tried changing it to still use the other "text" field, but to include stComments but it didn't work.
Nov 12 '08 #7
tdw
206 New Member
YES!! I figured it out. I had to change it to:
Expand|Select|Wrap|Line Numbers
  1. If Response = vbYes Then    ' User chose Yes
  2.                     stComments = Nz(Me.COMM_1)
  3.                     Me.COMM_1 = stWarn & Chr(13) & stComments
  4.                 End If
  5.  
The only problem now is that Chr(13) puts a vertical line in there instead of skipping to the next line.
Nov 12 '08 #8
puppydogbuddy
1,923 Recognized Expert Top Contributor
Good work! change code as follows:
Expand|Select|Wrap|Line Numbers
  1. If Response = vbYes Then    ' User chose Yes 
  2.                     stComments = Nz(Me.COMM_1) 
  3.                     Me.COMM_1 = stWarn & vbCrLf & stComments 
  4.                 End If 
Nov 12 '08 #9
tdw
206 New Member
It works! Thanks. I ended up deciding it worked better like this:
Expand|Select|Wrap|Line Numbers
  1. If Response = vbYes Then    ' User chose Yes
  2.                     stComments = Nz(vbCrLf & vbCrLf & Me.COMM_1)
  3.                     Me.COMM_1 = stWarn & stComments
  4.                 End If
  5.  
Now, a similar question that I can't seem to figure out:
In the following code, how do I get it to copy the text I just typed over to the Subdivisions form that opens, so that I don't have to type it twice?
This would only apply to when the subdivision I type is not already in the subd table.
Expand|Select|Wrap|Line Numbers
  1. '   Check to see if this subdivision is already in the subdivisions table
  2.     If DCount("*", "subd", "[subd_name]='" & Me!SUB_NAME & "'") = 0 Then
  3.     '   Yes No Box
  4.         Dim Msg, Style, Title, Response
  5.         Msg = "This Subdivision is not in the list. Do you want to add it?"    ' Define message.
  6.         Style = vbYesNo   ' Define buttons.
  7.         Title = "Add Subdivision"    ' Define title.
  8.         Response = MsgBox(Msg, Style, Title)
  9.             If Response = vbYes Then    ' User chose Yes
  10.                 DoCmd.RunMacro "Open Subdivisions Form"
  11.             End If
  12.  
Nov 12 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
12586
by: sao | last post by:
I am currently using Access 2000. In my table it is the following fields that are set up: 1 - Staff Name 2 - Department This table is already populated with 100+ records (staff along with department.)
2
6592
by: G.Gerard | last post by:
Hello Does anyone know how to get an entire memo field to be displayed in a combo box drop down list? Example - if the memo field contains the following : This is a test to see if
1
2031
by: Jason | last post by:
I have a form that is used for entering and editing site address information. The data in the form is from one table, named Total_Site_Address. There are fields in this table (and controls on the form) for entering in a new site address or choosing an existing site address. There are two fields that address the existing site addresses, one named ADDRESS, the other named TAX_NAME (contains municipality info). The ADDRESS field is setup...
3
3154
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and populate a combo box with these names. (this way, I can display all the EMPLOYEE_NAME values) (2) In general, can I do additional processing on column values from
4
2383
by: steverossiter | last post by:
Hi and thanks, I have a Journalist database for tracking writers from various magazines and would like a field that could hold the text of their articles as they are published. The Memo field would allow 65K characters but with time even this would not provide the necessary space. The field need not hold graphics, although that would be nice if possible, and I will not need to run queries against it. It is simply
9
5725
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo field is printed within the detailed area. The problem is, the apllication is not setup properly, thus the users are entering data within the memo field as: location1 1/1/2005 1/1/2006
10
3044
by: ARC | last post by:
This is mainly a speed question. In this example: I have a QuotesHdr table that has a few memo fields. If these memo fields are used extensively by some users, and if their are a large number of records in QuotesHdr, should I break out the memo fields into a separate table? The thinking here is that, for Quotes selection dropdowns that display all entries in QuotesHdr for selection, I would think that the entire record comes down over...
0
1350
by: daverskully | last post by:
I have two tables created and want to link two forms created from these tables so that specific fields are populated once one field is selected, but not all fields being populated, with a new record being saved into one of the tables. Tables: 1. StaticInfo contains fields: 1) Department 2) DepartmentNumber 3) AccountExecutive and 7 yes/no fields
2
1808
by: daverskully | last post by:
I have two tables created and want to link two forms created from these tables so that specific fields are populated once one field is selected, but not all fields being populated, with a new record being saved into one of the tables. Tables: 1. StaticInfo contains fields: 1) Department 2) DepartmentNumber 3) AccountExecutive and 7 yes/no fields
0
7880
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.