Forms :: Add Record To Table From A Form Using Unbound List And Text Boxes?
May 14, 2013
I have a form with 1 unbound listbox as drop down list (entypolst), an unbound text box(entypotxt) and a command button. The list box reads items from a table. I want to change a value (text) on listbox, input a text on textbox so pressing the button add a new record in a table (Table1 fields Category,Product) showing in my form as subform (SFTable1) in datasheet view. For that reason a made the following code:
Code:
Private Sub AddBtn_Click()
Dim ans As Integer
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
[code]....
I take the error msg for 0 items selected in listbox and exit the sub.
As a part of reducing traffic on file server, I am planning to read less record on the form and hence I tried removing forms record source. (Attached sample db)
I kept all unbound textboxes onto the forms and save new record to the table using codes back of the command button. This is working great with main form. But doesn’t with sub form. I tried removing record source of sub form and keeping unbound text boxes to appear record if it exists.
If you enter 1 in InvNum text box on main form, you will find it brings record. I don’t want to show the record on the sub form unless I call it from main form.
How can I use the same trick of unbound text boxes with sub form too?
I created an unbound text box on a form that automatically pulls the current logged in user by using this:
Private Sub Txtuser_Click() Me.Txtuser = Environ("Username")
The form grabbs the logged in user with no problems, however, I ultimately want this information to also end up in my table. So the form has three boxes (to keep it simple). The user will type their first name and last name manually on the form which the record source is this "table" where their name goes to the table last name =Field 1 and first name=Field 2 respectively. I want the unbound box from the form to place the logged in user in Field 3 for the current record.
I have a form that contains a combo box (cboEmployeeName) that pulls data from a query and populates three text boxes (Work Area, Last Name, First Name), This part works fine. Because the text boxes are being populated by the Combo box, they are not bound to the record source tblTrainingSchedule). I need the info that is in the text boxes to populate the respective fields in the record source.
I tested by adding "=tblTrainingSchedule!WorkArea=[cboEmployeeName].Column(3)" (column 3 is the work area) to the "after update" control but it does not populate the data.
I am running in to a brick wall with this. I have an unbound text box with the control source set to =IIF([text42]=0,0,[text42]/[text44])*100 and in continues to return a #name? error.
I am not sure how to get this expression to work. I have even tried to put =[text42]/[text44] and I still get the #name? error.
I have a table here tblTemp with a field client. This table can have from 1 to 100 records at times as it keeps getting cleared for the purpose of this exercise.
I also have a form frmLabel1Data with an unbound text box txtclient.
I was hoping to get the first record of the table into this text box upon opening the form.
I tried creating a query which gave me the following sql;
SELECT First(tblTemp.client) AS FirstOfclient FROM tblTemp;
I also tried placing it in this code with no luck
Private Sub Form_Open(Cancel As Integer)
Dim SQL
SQL = "SELECT First(tblTemp.client) AS FirstOfclient FROM tblTemp;" MsgBox SQL
End Sub
Does anyone know why I cannot see the same result as when I open the query it gives me my client name but the code above does not????
I want people to be able to search, or jump to a record by the PO #
I am hoping to just do it in the form, and by that I mean, the user is on the Purchase Order form and needs to look at a previous Purchase Order for editing, deleting, etc. and to just type it in the text box, hit the search button, and there it is.
2 Forms 1) - Employee Details (source control is "QEmployees Extended") 2) - Employee List (source control is "QEmployees Extended")
in Form "Employee Details" there is field named "HireDate" this field is also found in the table (records) "Employees" and "QEmployees Extended".When Form "Employee Details" is ran the "HireDate" appears as it should in the "HireDate" text box.
What I want to do is add a unbound text box to Form "Employee Details" named "txtYrsEmp" (Years Employed). and perform a calculation that will take the "HireDate" (date) and compare it to "Todays Date" and come up with the number of years employed rounded by 2 and show this result in the unbound text box called "txtYrsEmp"
Now I did a Qurey just to see if I could calculate what I wanted- "QYrsEmp" where in the first column I entered in the Field row (top) Expr1: EmployeeID from table Employee and in the second column I entered in the Field row (top) txtYrsEmp: Round(DateDiff("d"'[HireDate],NOW()/365.25,2))
Now the query returns the exact results I want so I know the calculation is possible at least here in the query.
I have a report that selects and shows records where a specified date field is within the range of 2 dates that the user enters.I created 2 unbound textboxes on the report with a Shortdate format and InputMask 0000-00-00;0;_.When user enter correct dates, then everything works fine: selection is properly done, the right records show up.But I have 2 problems:
1-the input mask is not working: the user can input anything! 2-the 2 unbound textboxes do not show the dates entered by the user.
It seems the value entered bu user does not go straight into the unbound textbox. How do I either intercept the value entered by the user directly into the unbound textbox or via a variable?
I have a form with a List Box (List BoxA) that returns a value from a query. I then have a Text Box (Text BoxB) that uses the value from List BoxB and multiplies it by let's say 2. It works giving me the correct value but only becomes visible after I click inside List BoxA. How can I make it visible as soon as the form is opened? I tried refreshing the form data, didn't work and I tried a requery macro which didn't work either.
I have a tabbed form from which the user can select a contact's record from a subform on the first tab, click a edit command button, and the unbound text boxes on the top of that tab populate. The user can then click the second tab with employment history which has blank unbound text boxes and another subform which is linked by the contact id to the first tab.
The user can select a record in the second tab, click a command button and the text boxes populate no problem. The problem comes when the user changes the contact on the first tab, and then tries to edit a record on the second tab. Then I get a run-time error '-2147352567 (80020009)' saying the value you entered isn't valid for this field. Why it would work the first time by not the second?
i have a form contains unbound listbox , that accumulates values of a field in that form "SalName" , when i move between records of this form i want the value that is in the current record is distinguished in the Listbox ( only where the SalID=SalID).distinguish by A special colour ,Font,undeline.
why =listboxname.column(0) in the control source of a textbox will give me the value "#name?" ? I've used it successfully on another form..but for some reason its not working for me.
I've created a form with two textboxes and a listbox. What I want to do is to show in the listbox the registers filtered by the 2 textboxes. But I would like that the listbox refreshes while typping in the textboxes.It was no problem to do filtering with only one textbox. The rowsource of the listbox is a query in which I set in the criteria Like [Forms]![Form1]![Textbox1].[Text] & "*"Then I write the code for the change event of the Textbox1:
Private Sub Textbox1_Change() Listbox1.Requery End Sub
With this I have no problem. The problem is when using the 2 textboxes. I write the same in the criteria, Like [Forms]![Form1]![Textbox2].[Text] & "*", on another field but it doesn't work. I also write the code for the second textbox:
Private Sub Textbox2_Change() Listbox1.Requery End Sub
The listbox doesn't filter with both textboxes. When you type in one of them, the listbox filters from it, but when you type in the other textbox, the listbox shows the whole table filtered with the characters of the second textbox.
My database has Main form and a Sub form. On main form i place one unbound text box named investigations. In subform of which datasheet there is a column named TestCode. I want unbound text box (Investigations) to display row values which selected in a column (TestCode) of subform.for example:Investigation field should display "CBC,HB,ALP".
I am trying to obtain totals from two columns in the list box into text boxes on the main form, but my third argument is not working as expected.The source of one of the tex boxes is:
I want to show some text from another table based on the values of the bound fields in each record of a continuous form. I thought it would be easy, but I can't get it to work.
I step through the records in the bound recordset and use some of the values to query another table. Then I use the value from the query to populate the unbound text field.
It works fine for each record. But every time the unbound field is updated, all the records in the continuous form are updated.
I'm stuck on this one. It's probably something simple to fix - if you know what to do!
What i'm trying to do is fill several unbound text boxes on a form.
I have an "Employeetbl" with "Employeename" and a "Projecttbl" with "Projectname". what i want to do is have about 10 text boxes from left to right on my form. Then fill these with all the employee names from my "Employeetbl". Underneath this i will have about 10 text boxes from top to bottom and i'd like to fill these with the project name from the "Projecttbl"
I am having a little problem with making an audit trail for a form with some unbound text controls on it.
Since .OldValue won't work on unbound text boxes, google suggested that I put the old value in the control's tag property. This is what I came up with:
Code: Dim ctl, tbox As Control Dim strName, strOLD, StrNew, NewTag As String Dim NextOne As Label For Each tbox In Me.Controls If TypeName(tbox) = "TextBox" Then Select Case tbox.Value
[Code] ....
The first loop is supposed to dynamically assign the tag value, with whatever the textbox value is, however it doesn't. I've asterisked out the line i think may be the issue.
I have 10 unbound textboxes with the Tag Name "LoopID" in my report. I have to display the "PatientNumbers" field from the table tblPatient in those text boxes. Below is my code.
When I run the report, I get the error message: Run-time error '2448.' You can't assign value to this object and the code "Ctl.Value = rst!LCANumber" is highlighted.
Private Sub Report_Current() Dim strSql As String Dim dbs As Database Dim rst As Recordset Dim x As Integer Dim Ctl As Control strSql = "Select PatientNumber from tblPatient"
On a form I'm asking a user to enter dates in 2 different textboxes, say, [text1] and [text2], both formatted to short date. In a third textbox [text3] I need to see the date of the greater of the two, and in a fourth [text4] I need to see the date of [text3] if it falls on a Monday through Friday, or the date of the previous Friday if [text3] falls on Saturday, and the date of the following Monday if [text3] falls on a Sunday.
...a couple quick examples;
If text1 = 2/20/2015 and text2 = 2/27/2015, text3 should evaluate to 2/27/2015, and text4 should evaluate to 2/27/2015 or If text1 = 2/20/2015 and text2 = 2/28/2015, text3 should evaluate to 2/28/2015, and text4 should evaluate to 2/27/2015
My attempts to compare text1 and text2 revolve around an IIF but result in an error...
Entering this into [text3]... IIF([text1]>[text2], [text1], [text2])
results in "#Name?" error, which I interpret as meaning the date from the source cannot be pulled into the formula.In attempt to check the day of week, I used =Weekday([text3],1) which results in a number. I haven't been able to do an IIF on it as it errors with #Name? again.
The layout: I have form1 listed in continuous view. I have about 10 fields being listed. I have unbound text boxes for each field in the form header designated as a filter for each field.
Ideal world: Have each filter update records as you type. But I would also like for a "cascade" effect on the filters as well. Being that I can type in a few letters in FilterField1, and type in a few letters in FilterField2 and it would only display the records where the criteria is met for both filters.
What I'm not looking for: Only applying 1 filter at a time for 1 field. I have this setup now, but would like it to be more versatile allowing several fields to be filtered at once.
I have some code for a button on click event to open a form and select the record which corresponds to a value in an unbound text box. The code is:
Private Sub Command25_Click() On Error GoTo Err_Command25_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "frmOpenPatientRecord"
[Code] ....
This works fine when I put in a 10 digit NHS number but opens a blank record when I enter a four digit or six character/digit PatientNumber. Both patient number and NHS number are text fields in the underlying table.
I have a form that utilizes a combo box called cboProgAddr (for Program Address). The cbox has 5 columns each of which fills in an adjacent text box. Since I needed the option of making corrections to these text boxes once they were filled in I need to set them up as unbound via the following code in the After Update event of cboProgAddr:
Private Sub cboProgAddr_AfterUpdate() Me!txtProgStreet.Value = Me!cboProgAddr.Column(1) Me!txtLocStreet.Value = Me!cboProgAddr.Column(1) Me!txtProgCitySt.Value = Me!cboProgAddr.Column(2) Me!txtLocCitySt.Value = Me!cboProgAddr.Column(2) Me!txtProgZip.Value = Me!cboProgAddr.Column(3) Me!txtLocZip.Value = Me!cboProgAddr.Column(3) End Sub
As you can see it puts each field of data into two separate text boxes. Here's the issue: If I have to go back to the form after the original data entry the following boxes are blank...
txtProgStreet txtProgCitySt txtProgZip
while the following retain the orginal data...
txtLocStreet txtLocCitySt txtLocProgZip
The original cboProgAddr maintains its original data. All six fields above are stored in the same table as text field. I'd like all the boxes to maintain the data from the original input.
I'm totally baffled why this is so. I've attached images of the combo box control functions if that helps.