473,385 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Updating a bound textbox from another form

Following on from http://bytes.com/topic/access/answer...nbound-textbox

It's going to be complicated to explain but I'll give it a go and hope you guys understand what I mean.

So with this same data entry form, when the user enters into the textbox a location that is not already in my tblLocation, a dialog box opens up giving the user the option to add the new location to the table or to select an existing location from a list box. Once the user does either of these options, I then need the txtLocationID textbox to update to the new LocationID of the new/existing location and also need the unbound textbox to update to the new/existing location. Unfortunately, I can't get this to work... hopefully that's where you guys can help me!

The first function below is what I am using to determine whether or not the entered location already exists in the table. If it does, it updates the txtLocationID box (this all works fine. It it doesn't already exist, the new dialog box pops up. This also works fine for now.

Expand|Select|Wrap|Line Numbers
  1. Private Function fQryGetLocationID(Optional Cancel As Integer)
  2.     Dim db As Database
  3.     Dim qdf As QueryDef
  4.     Dim rs As DAO.Recordset
  5.     Dim intX As Integer
  6.  
  7.     Set db = CurrentDb()
  8.     Set qdf = db.QueryDefs("qryUpdateLocationID")
  9.     qdf.Parameters("test") = Me.txtLocation
  10.     Set rs = qdf.OpenRecordset()
  11.  
  12.     If rs.RecordCount <> 0 Then
  13.         With rs
  14.             .MoveFirst
  15.             Me.txtLocationID.Value = .Fields("LocationID")
  16.         End With
  17.     Else
  18.         MsgBox "No matching location!"
  19.         glTestNoLocation = Me.txtLocation.Text
  20.         Cancel = True
  21.         DoCmd.OpenForm "frmNoLocation", , , , acFormAdd, acDialog
  22.     End If
  23.     rs.Close
  24.     db.Close
  25.     Set rs = Nothing
  26.     Set qdf = Nothing
  27.     Set db = Nothing
  28. End Function
  29.  
The popup box has a textbox called txtUnsavedLoc, a save button for the new location called cmdSave, a list box populated with similar locations to the originally entered location and an ok button to select an option from the list box.

On loading, the list box is populated using a query where the unbound text box from the data entry form is tested using a Levenshtein function and produces locations with <5 differences.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. txtUnsavedLoc = glTestNoLocation
  4.  
  5. Dim db As Database
  6. Dim qdf As QueryDef
  7. Dim rs As DAO.Recordset
  8. Dim intX As Integer
  9.  
  10. Set db = CurrentDb()
  11. Set qdf = db.QueryDefs("qryLevLocation")
  12. Me.txtUnsavedLoc.SetFocus
  13. qdf.Parameters("LevLocation") = glTestNoLocation
  14. Set rs = qdf.OpenRecordset()
  15.  
  16. 'remove all items in the list box before querying to add them
  17. With rs
  18.     With Me.lstResults
  19.         For intX = .ListCount - 1 To 0 Step -1
  20.             Call .RemoveItem(intX)
  21.         Next intX
  22.     End With
  23. End With
  24. Me.lstResults.Requery
  25.  
  26. If rs.RecordCount <> 0 Then
  27.     With rs
  28.         .MoveFirst
  29.         While Not .EOF
  30.             Me.lstResults.AddItem .Fields("LocationID") & ";" & .Fields("FileLocation")
  31.             .MoveNext
  32.         Wend
  33.     End With
  34. End If
  35.  
  36. rs.Close
  37. db.Close
  38. Set rs = Nothing
  39. Set db = Nothing
  40.  
  41. End Sub
  42.  
If the user selects an option from this box and then presses the Ok button, I need the selected option to populate the unbound textbox with the text and the bound textbox with the locationID. I have used the following. It replaces the unbound textbox but the bound textbox doesn't change.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2.  
  3. If Me.lstResults.ListCount <> 0 Then
  4.     If Me.lstResults.ListIndex <> -1 Then
  5.         If CurrentProject.AllForms("frmAddFile").IsLoaded = True Then
  6.             [Forms]![frmAddFile]![txtLocationID] = Me.lstResults.Column(0)
  7.             [Forms]![frmAddFile]![txtLocation] = Me.lstResults.Column(1)
  8.         End If
  9.         DoCmd.Close acForm, "frmNoLocation"
  10.     End If
  11. End If
  12. End Sub
  13.  
Any ideas where I'm going wrong?
Jan 28 '15 #1
2 1825
Seth Schrock
2,965 Expert 2GB
Lets try something. Between lines 6 and 7 of your last block of code, try putting
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Me.lstResults.Column(1)
When you run it, it will put the value in the immediate window in your code editor. If you don't see it on the bottom of your code editor, then press Ctrl + G to view it.
Jan 28 '15 #2
The value is Cirencester, which is the text value I selected in the list box. Also apparently I have a runtime error on line 7:

error 2115: the macro or function set to the before update or validation rule property for this field is preventing microsoft access from saving data in this field.

I thought it might just be me doing something wrong with my function, so I just copied the code into the before update section and deleted the function line but it's still appearing with this error!
Jan 28 '15 #3

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

Similar topics

5
by: John Sheppard | last post by:
Hi there Does anyone know how to fill a bound textbox automaticlly. In an unbound textbox I would put in the control source =Sum(price, tax) (or some such function) and access updates it...
5
by: Taryon | last post by:
Consider the Form A calling the Form B. In the Form B i need to access the values of the Form A textbox. Normally i create the textbox as public. BUT in this case, the textbox of Form A will be...
1
by: Rich | last post by:
Hello, I have some datefields in a dataset (ds1). I bind some textbox controls on a windows form to these date fields in ds1, but I only want to see 01/01/2004 instead of 1/1/2004 8:00:00 AM. ...
7
by: Howard Minor | last post by:
Not sure why this is an issue, but apparently when you paste a string into a textbox that is bound to a dataset/datasource, it does not save into the dataset. I've tried several things including...
2
by: lucaoscar | last post by:
Hi all, as you can see from the level of my question, i am pretty new to c# and programming in general. situation: i would like to update the UI of a form (main form of my application) from a...
0
by: colleen1980 | last post by:
Hi: There are two textboxs in my main form. One is bound and another is unbound. There is no entry in the unbound textbox as values come into automatically after entering some information in the...
4
by: Peted | last post by:
Hello i have a textbox on a form1. I want to pass the name of that textbox as a paramter to another class (not a form class) and once gotten this paramter i want to update the textbox on...
4
by: Organizer | last post by:
I am using Microsoft Access 2007. I have a list in a dropdown combobox (Field_One) in a form (Form_One). Users have the option to click a button if the item they need does not appear in the combobox,...
0
by: Saboor Mohideen | last post by:
Can someone tell me which event occurs on Total TextBox: Main Form Name Type Event Used Event Set All three textboxes are bound to a table CashAmount TextBox ...
7
by: DavidAustin | last post by:
Hi all, The database I am making is essentially for data entry of files and which boxes they have been placed into for storage. I have multiple textboxes on my form but I am only focused on a...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.