Modules & VBA :: Using Unbound Form Values To Update Table
Jul 16, 2015
I have an unbound form in which a user enters data relating to a credit dispute, and when they hit the Save button I have a sub that is intended to insert that data into a table. This is a bit out of my comfort zone, so I found some code from another forum and adjusted it to my needs. However, I'm getting errors.
The table name is tbl_complaints. The fields from the form are:
Private Sub cmdSave_Click()
Dim StrSql As String
On Error GoTo ErrorHandler
StrSql = "INSERT INTO tbl_complaints " _
& "(ACCT_NUMBER, CLIENT_NAME, EOSCAR_TYPE, EOSCAR_CONTROL_NUMBER, METHOD_OF_RECEIPT,
[Code] ....
The error I get is error number 3075, and it says I'm missing an operator in the section that references cboResponseType, but I can't seem to figure out what I'm missing. My head is spinning from staring at these parentheses and apostrophes for so long.
How to do an UPDATE using VBA on a form to update a specific record on the table using an unbound field on the form to filter the update.
Every time the code runs, it tells me: Run-time error '3144': Syntax error in UPDATE statement and takes me to the "CurrentDb.Execute strSQL, dbFailOnError" line at the end of my sample below.
I am working on a timesheet application which allows users to insert multiple timesheet entries in a grid style format. the first row is visible and to add another row users click on a command button which makes the next row of fields available and ready to fill in and so on and so forth. I need the fields to be unbound and then when the user clicks on a save button for example then it inserts those values into the relevant table. Table name is tbltimesheet, field names are id, companyname, project, activitydate, activityhours, activitynotes, username, userid
So I have this code in an afterupdate event in an unbound text box to update the value of a table if the textbox is updated:
Code:
Private Sub txtCustRepID_AfterUpdate() 'Go to Calls table and find original value for CustRepID 'Fin the Call ID first Dim CallIDVar As Long Dim ContactIDVar As Long Dim CustRepIDOr As String CallIDVar = Forms![Contacts]![Call Listing Subform].Form![CallID]
[code]...
This code works well when entering numbers in the text box but it returns error 3061; "Too few parameters. Expected 1" when along with the numbers there is a letter in the textbox.The error happens in this part of the code:
Code: 'Accept change and add new value to table CurrentDb.Execute _ "UPDATE Calls " & _ "SET CustRepID = " & CustRepIDNew & " " & _ "WHERE CallID = " & CallIDVar, dbFailOnError
The underlying table has text as type of data for this field.
I have a form, which has a search box. This allows you to search through the id numbers of each record. Once an ID has been selected a bound textbox displays the id number. Other unbound textboxes then display other information from the table with the relevant record.
What I want to do is then allow users to change information in textboxes and update the record.
I have created a forum that all fields are unbound. On completing it is written to the table using a RunSQL command. This writes to the table with no problem but when it does so it is creating another entry with zero content. This is the save steps with open new form
Code: Private Sub SaveRecordAddNew_Click() Call PreSaveCheck If Me.saveCheck = False Then Exit Sub Else Call WriteToTable
I'm making a very basic sales system for my school project and I'm currently working on the stock management part, as I said it's very basic.
My task -When the user receives a stock delivery they need to update the stock numbers. the value they need to update is the StockNumber value in the Products table. to so this I want to make a form that displays all the product names in a table with a textbox or cell next to it in which the user can enter the amount of that item that has been delivered. And at the bottom of the form there is a button which will add all these new values to the existing values.
1. There is no set number of products, the user is able to add new ones, this is preventing me from just making a separate textbox for each existing product
2. I have attached a jpeg I made in paint to illustrate how I want to the form to work as well as my system as it currently stands, there are a few unused forms and queries.
My form has a button that opens another form on which I enter meeting RSVPs. Then that form is exited. I have an unbound text box on the main form that I want to show the total number coming. I have a summation query that totals the number. I have tried everything I can think of to force the text box to requery. I tried putting the dlookup in the textbox itself, then I removed that and tried all of the things below, both in the gotfocus event and the onCurrent event. What else can I do to trigger the recalc?
Private Sub Form_GotFocus() Me.numcomingtxtbox.Value = DLookup("howmanycoming", "numcoming") & " Coming" Me.numcomingtxtbox.Requery Me.Recalc End Sub
As the unbound parent list box record selection is changed, I want the sub form to refresh. Do I put code in the Subform Current Record event?
Master Form Name: frmsr_NewWellEntry Unbound Listbox - when record selected the primary key populates txtNavWellID (unbound) on parent form
subform Container fsubsrNavSHLBHL Link Master Fields =Forms![frmsr_NewWellEntry].[txtNavWellID]
The read-only form in the subform Record Source is something like: select * from vsrNavigatorSHLBHL where Well_ID =90243..Key The Form used as the subform above will be re-used in multiple parent forms. The parent form data is form SQL Server, the subform from Oracle.
I am updating a value in an unbound control on an unbound form. When the value in the control is changed I want a sequence of code to execute. Specifically changing the record source of a subform and refreshing it.
The problem I have is that when the value of the unbound text box is control is changed (I am using a button to change the value as a test) the after update event on the text box does not do anything.
I did a simple test using a button to change the value in the text box and in the afterupdate event of the text box asked it to output the value of the textbox to a message box as shown below.
The problem is this does not work, nothing happens. If I tab out of the text box or change the value with the keyboard however the msgbox appears. Just not via a vba change.
Code: Private Sub Prod_ID_AfterUpdate() Dim pid As String pid = Me.Prod_ID MsgBox pid End Sub Private Sub Button_Test_Click() Me.Prod_ID.SetFocus Me.Prod_ID = "TEST" End Sub
I have a form that has unbound text box controls. The user enters numeric data in each of these text box controls. I want to be able to store the values that the user enters for future use. I am using the following code which was provided on Richard Killey’s web site. The problem is that the values that the code stores in the unbound text boxes is populated back as text values rather than numeric values. Here is the code that saves the values. Code:Private Sub cmdSave_Click() '--- only process Save if there is data in scheme name If IsNull(txtScheme) Then MsgBox "Please Enter A Scheme Name" txtScheme.SetFocus Exit Sub End If Dim rst As Recordset '--- use the primary key (which is always an autonumber field) to find the record '--- if it is a new record, this will find no records, as txtID will be 0 Set rst = CurrentDb.OpenRecordset("select * from tblschemes where ID=" & txtID) If chkNew = True Then '--- do we add a new record and save an existing one rst.AddNew Else rst.Edit End If '--- transfer data from text boxes to table fields rst!MVol = txtMVol rst!TVol = txtTVol rst!WVol = txtWVol rst!ThVol = txtThVol rst!FVol = txtFVol rst!SVol = txtSVol rst!SuVol = txtSuVol rst!Scheme = txtScheme rst.Update '--- save the record rst.Close '--- close the recordset Set rst = Nothing '--- reclaim the memory the recordset was using chkNew = False '--- reset the new flag '--- enable the list box and the Add New button and the Close button '--- must be done before moving focus to the list box lstData.Enabled = True cmdAddNew.Enabled = True '--- make sure the newest data is in the list box lstData.Requery '--- set the focus to the list box lstData.SetFocus lstData = lstData.ItemData(0) Call lstData_AfterUpdate '--- disable the text boxes and the Save button, and make Edit button enabled txtMVol.Enabled = False txtTVol.Enabled = False txtWVol.Enabled = False txtThVol.Enabled = False txtFVol.Enabled = False txtSVol.Enabled = False txtSuVol.Enabled = False txtScheme.Enabled = False cmdSave.Enabled = False cmdEdit.Enabled = True End Sub And here is the code that populates the values back into the unbound text boxes after an update. Code:Private Sub lstData_AfterUpdate() '--- whenever a new item is chosen in the list box, display the data in text boxes txtScheme = lstData.Column(1) txtMVol = lstData.Column(2) txtTVol = lstData.Column(3) txtWVol = lstData.Column(4) txtThVol = lstData.Column(5) txtFVol = lstData.Column(6) txtSVol = lstData.Column(7) txtSuVol = lstData.Column(8) txtID = lstData.Column(0) '--- primary key is in the first column (always) End Sub How do I change the code so it stores the values as numeric rather than text ? Thank you for any help that can be offered.
I have a query with an INNER JOIN and ORDER BY that is working great. Now, using the same JOIN, I need to update values in one table with the values in another. I thought it would be simple until I learned you can't do an ORDER BY with an UPDATE. Is there another way to achieve the same result? If you remove the 'ORDER BY', the statement below doesn't produce an error but the results are not correct:
UPDATE TableA INNER JOIN TableB ON (Left(TableA.CDN,6))=(TableB.CDN) SET TableA.HCC = TableB.HCC WHERE TableB.HCC Like '241*' AND TableB.BBB = 'X' AND TableA.CCC = "1234" AND TableA.HCC IS NOT NULL ORDER BY TableB.HCC, TableA.CDN;
I have two tables that I want to update from data in an unbound form. How do I capture the ID of the new record created in table 1 in order to write it to a field in the new record being created in table 2.
I am making a dp for end of day sales, and i want to compare data in a table to the numbers inputted in a form and see whether this value is higher or lower. the table displays the target sales figures for each day, and the form allows the area mangers to enter in the current day figures.
I'm trying to write some Code with the target to take a value from a textbox (out of a form) and a pregiven value (in this case = 2) and enter them in a new record in a table. But only if there is not already a record with the exact same combination of these to values. When done, the same button should proceed you to the next form (but this code is not already implemented in the fragment below) even if no values are added because they already exist in this combination.
Code: Public Function GetID_PatientStudiesGroup&() GetID_PatientStudiesGroup = [Forms]![frm_PatientStudiesGroupTZP]![ID_PatientStudiesGroup] End Function Private Sub BPRS_T1_Button_Click() Call GetID_PatientStudiesGroup& Dim strSQL As String
[Code] ....
As you can see, I tried to use a function to refer to the value out of the form, because I didn't find out how to refer to a form in an SQL Code.
Just to give you a better overview: The table where the information should be added is named "tbl_PatientStudiesGroupTZP". The form where you find the Textbox "ID_PatientStudiesGroup" (with the value I need to transport) is named "frm_PatientStudiesGroupTZP". Every part (except the WHERE NOT EXISTS part) worked perfectly for itself, but not when thrown together.
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!
While the form itself is bound to tbl_Orders I decided to use unbound text boxes to enter the data (knowing I was in for some work!). Reason is that if textboxes were bound would need to use a subform with multiple combo boxes and that UI did not seem suitable for the application.
I’ve completed the code to add new records to tbl_Orders and tbl_Junction from the unbound textboxes. I'm using the VBA .AddNew method and is working well. Now I need to integrate code that will allow users to edit existing records while they are viewing them on the form.
I have the code to look up the record set I want to edit in tbl_Junction and am familiar with the .Edit method but the issue is that the required changes MAY include not just editing existing records but also deleting and adding new records. For example, the initial order may have been for Apples and Oranges and the revised order may change the number of Apples, eliminate Oranges entirely, and add some Bananas. So, it seems I need to .Edit Apples, .Delete Oranges, and .AddNew Bananas?
Should I try to write code to determine where I need to .Edit/.AddNew/.Delete? -- not looking forward to that. Thought maybe could delete the entire junction record set and then just .AddNew for everything per the revised order. That should work as the display on the form would be correct for the whole order. But maybe would cause a problem as would remove the FK in tbl_Junction that corresponds to the PK in tbl_Orders?
I've tried using the vba to have unbound forms information pasted to a table. The Vendor, Channel and Department are unbound fields in the form and I can't, for the life of me, figure out how to get them to append to the table.
I've tried using solutions provided prior but I must be missing something. Here's my database. I'd like for it to append to the table then ready the form for the next entry.
I'm trying to update the account number via an input box with a do loop but I don't have the code right. The at the input box, the user will type in a 4-8 digit number and it will update all the account number fields in a table that are null.
I have a combo box which gets its values from sql server using a query which is called "get_query_reason", which works fine. Now I want to update combo box values based on a user selection, st string. Have written the code, but does not work:
Dim qDef As QueryDef Dim Query As String Dim st As String Dim rs As Recordset st = "SOV" Set qDef = CurrentDb.QueryDefs("get_query_reason")
I want to know a way of populating unbound textboxes with data from a table without using the easy assigning data in the property of the box. I want it to be all done with code, which to me isnt a huge deal but I've yet to find answers on the web pertaining to this issue.
for example:
Say i was searching a primary key in one box and based on what ever is typed in i'd like it to populate the rest of the textboxes.
The attached Access XP file demonstrates my problem. I've included a form to make testing easier.
Each record in the Projects table has one or more linked entries in the Keywordlink table, showing keywords that apply to that record. Each record in Projects has a Yes/No 'Utility' field.
A third table, Keywords, supplies the keywords that the user can apply to records in Projects, using the subform on the main form. The Keywords table also includes a True/False 'Utility' field. I have set this to True for for the first three keywords.
I need a query, a series of queries or some VB code that updates Projects_Utility for all records to True if and only if the record's linked entries in Keywordlink include all of the keywords for which Keywords_Utility is True (a boolean 'and', as opposed to an 'or'). Otherwise, Projects_Utility must be set to False.
In the attached file, with the current settings in the Keyword table, the 'GetSelectedProjects' query should then produce single-row listings for ClientA and ClientF.
I'd appreciate any help you can give me on this. I'm not a programmer, but I can manage a bit of VB code if I have to.
I have a onclick tied to a label (for decoration purposes) that when clicked it launches VBA that essentially updates a form. All that part works except it will not recognize any changed value of the field I was last in?
Just to try to explain best as I can what happens.
- Form gets opened - I change field (quantity field) - I click the Label - It reverts to pre-existing value.
if I click off of the text field first then do the onclick - it recognizes just fine.