473,499 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populate values on a text field with a combo box from another form

27 New Member
Hello,

I am trying to bring two values in a txtfield from one form to another form using a combo box to select the option I want, then when populate the values I want to see but it is not the option I want I have a clear button that does not work, when I choose the option on the combo box and populates the values from the other form it records the data as soon it is populate, I do not want that, in case I choose the wrong option. need help please

code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboGoToPosition_AfterUpdate()
  2. On Error GoTo ErrHandler:
  3.  
  4.     Dim str As String
  5.     str = cboGoToPosition.SelText
  6.     Dim dbTemp As Database
  7.     Dim rsTemp As Recordset
  8.  
  9.     'Open connection to current Access database and perform the search
  10.     Set dbTemp = CurrentDb()
  11.     Set rsTemp = dbTemp.OpenRecordset("SELECT [REPLACEMENT FOR],[Position Name] From tbl_GCDS_Operations_Positions_Fills " _
  12.                                       & "WHERE [REPLACEMENT FOR]= '" & str & "' and [Position Status] = 'Open'")
  13.  
  14.     Me.RecordSource = "SELECT * " & _
  15.                       "From tbl_GCDS_Operations_Positions_Recruit " & _
  16.                       "WHERE ((([Position Applied For])='" & Me.cboGoToPosition.Column(0, Me.cboGoToPosition.ListIndex) & "')) " & _
  17.                       "ORDER BY[Position Applied For];"
  18.     Me.Requery
  19.  
  20.     'Update fields if data is found
  21.     If rsTemp.EOF = False Then
  22.        Me.REPLACEMENT_FOR = rsTemp![REPLACEMENT FOR]
  23.        Me.Position_Applied_For = rsTemp![POSITION NAME]
  24.     Else
  25.        Me.REPLACEMENT_FOR = ""
  26.        Me.Position_Applied_For = ""
  27.     End If
  28.  
  29.     rsTemp.Close
  30.     Set rsTemp = Nothing
  31.     Set dbTemp = Nothing
  32.  
  33. Exit Sub
  34. ErrHandler:
  35.     MsgBox Err.Description
  36. End Sub
  37.  
  38. Private Sub cmdClearOpenPosition_Click()
  39.  
  40.  
  41.     Me.RecordSource = "SELECT tbl_GCDS_Operations_Positions_Recruit.* " & _
  42.                       "FROM tbl_GCDS_Operations_Positions_Recruit " & _
  43.                       "ORDER BY tbl_GCDS_Operations_Positions_Recruit.[Position Applied For];"
  44.     Me.Requery
  45.     Me.cboGoToPosition = ""
  46.  
  47. End Sub
Dec 8 '17 #1
1 2309
twinnyfo
3,653 Recognized Expert Moderator Specialist
ivonsurf123,

I would like to assist with your question, however, there seems to be a disconnect between your question and your code.

You stated:
I am trying to bring two values in a txtfield from one form to another form using a combo box to select the option I want
However, I do not see any references to that other Form, so I am not sure I quite understand your question.

There are some thing I can recommend based upon what I do see in your code which may be of help to you.

First, rather than changing the RecordSource of your Form every time you select something from your Combo Box, you should simply make tbl_GCDS_Operations_Positions_Recruit the RecordSource for your Form (in design mode).

Then, when you select an item from the cboGoToPosition Combo Box, Filter the Form. To clear the Form, remove the Filter:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboGoToPosition_AfterUpdate()
  2. On Error GoTo ErrHandler:
  3.  
  4.     Dim str As String
  5.     str = cboGoToPosition.SelText
  6.  
  7.     Me.Form.Filter = "[Position Applied For] = '" & str & "'"
  8.     Me.Form.FilterOn = True
  9.  
  10.     Dim dbTemp As Database
  11.     Dim rsTemp As Recordset
  12.  
  13.     'Open connection to current Access database and perform the search
  14.     Set dbTemp = CurrentDb()
  15.     Set rsTemp = dbTemp.OpenRecordset("SELECT [REPLACEMENT FOR],[Position Name] From tbl_GCDS_Operations_Positions_Fills " _
  16.                                       & "WHERE [REPLACEMENT FOR]= '" & str & "' and [Position Status] = 'Open'")
  17.  
  18.     'Update fields if data is found
  19.     With rsTemp
  20.         If Not rsTemp.RecordCount = 0 Then
  21.            .MoveFirst
  22.            Me.REPLACEMENT_FOR = ![REPLACEMENT FOR]
  23.            Me.Position_Applied_For = ![POSITION NAME]
  24.         Else
  25.            Me.REPLACEMENT_FOR = ""
  26.            Me.Position_Applied_For = ""
  27.         End If
  28.         .Close
  29.     End With
  30.  
  31.     Set rsTemp = Nothing
  32.     Set dbTemp = Nothing
  33.  
  34.     Exit Sub
  35. ErrHandler:
  36.     MsgBox Err.Description
  37. End Sub
  38.  
  39. Private Sub cmdClearOpenPosition_Click()
  40.  
  41.     Me.Form.FilterOn = False
  42.     Me.cboGoToPosition = ""
  43.  
  44. End Sub
I also made a few minor changes to Lines 18 through 29 above. However, this code assumes that there will never be more than one record that matches the criteria you state. What happens if there is more than one record?

Additionally, based on line 7 above, since you are using the text value of a Combo Box and not its corresponding Index, it appears that your Tables may not be properly Normalized. If you are unsure of what that means, please refer to this Insight: Database Normalization.

Please let me know if you have additional questions or require additional clarification.

Hope this hepps!
Jan 2 '18 #2

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

Similar topics

2
4242
by: NewBob | last post by:
Since Access automatically highlights all of the text in a text control (I use it to hold data from a memo field) when the control is activated, I've added the following code to put the cursor at...
4
2390
by: N. Graves | last post by:
Hello; I have a table that is equipment. This table has a filed called Owner and that Owner filed is Looked up from a table called employee. and the query request the serial number of the...
0
1275
by: matthewemiclea | last post by:
I have a Coninuous form that is based on a table with the following fields: ID (Text) Qty (Number) COMPLETE (Check Box) Users will be going to this form and checking the...
14
4644
by: simonmarkjones | last post by:
Hi, I'm having a bit of trouble editing an old database that was created quite a while ago by someone else. There is a form that lets the user select a member of staff and show details about the...
0
1282
by: Rob Webster | last post by:
I'm building a messenger like interface to a Chabot type program. It is appending text to the contents of a text field. How can I get it to scroll to the end after each append as there is no...
1
3421
by: John Davis | last post by:
I am writing a program that allows user to select the date in a calendar, and it will update the text fields automatically. I created 2 forms. The first form has 2 text fields (start date and...
4
1053
by: Michael Murschell | last post by:
If I have Form1 with a text field called Text1 on it, and I want to put information into that field from a second Form (Form2) how would I do it? I would have thought there would have been a way...
3
1674
by: RBirney | last post by:
When i load a form (frmcontract) in the program i write i can load a contract (cbocontract) as well as many other things, also in this form i can load another form to deal with expenditure...
1
1466
by: Peader | last post by:
Hi, I have a table with two columns "Job Order" and "Part Number", I'd like to populate a text field in a form with these values, whats the best way to do it? There's only ever 1 row in the...
4
2366
by: dekk | last post by:
I am trying to populate a text field from the combo selection. I have the following update event in the combo box Private Sub cboContract_AfterUpdate() Me!txtDesc = Me!cboContract.Column(1)...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
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...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5468
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,...
1
4918
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...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.