Modules & VBA :: Trying To Code INSERT INTO Table

Nov 11, 2014

I have a form that is calling data from a table. Then the user can determine if they approve the question or not. So what I am trying to do is take one combo box that has yes or no and write it to the database. I thought I had it correct, but appears I do not as it is not writing yes or no to the table. The field initially has no value and that is my query for calling the data for the user to select from. Here is the code that I have so far

<code>
'add approval to yes
CurrentDb.Execute "INSERT INTO travelerQA(approval)" & _
" VALUES('" & Me.cmbapproveda & "')"
</code>

View Replies


ADVERTISEMENT

Modules & VBA :: Parent Table Revision History - Insert Multiple Records Into Child Table

Sep 8, 2014

I have a parent table (tblLabels) and a child table (tblRevision) where the revision history for the parent table is kept.

The parent table is populated via an excel import and may have several records imported at once. Instead of having the user manually enter a new record note in the child table for each record imported into the parent table, I've created a form that collects the necessary data (date, person who added the record, person who authorized the record, and notes) and then creates a revision history for each new record.

This is what I have so far:

Code:

Private Sub cmdAddNotes_Click()
Dim strSQL As String
Dim RevisionDate As String
Dim RevisionRevisedBy As String
Dim RevisionDesc As String

[Code] ....

When I run the code nothing happens. No error, no new records create, etc. My suspicion is that I may need to use an INSERT INTO query instead of an UPDATE query, but I'm not sure how to go about matching up the foreign keys if that's the case.

View 14 Replies View Related

Modules & VBA :: How To Insert Records Into A Table

Dec 9, 2014

I am reading through a table looking for duplicate values in the FullName text field. I want to store in a new table the duplicate records I find, storing just the MemberNumber and the FullName. When the VBA code runs and finds duplicates, the SQL statement to insert a new record into the Duplicates table asks for the value of LastMemberNumber and LastFullName when it already has the values and has displayed them in the message boxes! What am I doing wrong?

The code is:

Private Sub Command0_Click()
Dim rs As DAO.Recordset
Dim dbs As Database
Dim LastMemberNumber As Integer
Dim LastFullName As String

[code]....

View 7 Replies View Related

Modules & VBA :: Get Latest ID And Insert To Another Table

Sep 6, 2013

How to Get latest id and inserted to another table like this image below

sdrv.ms/18HQ

See..i want in dbo_maid get id and insert to dbo_contract in maid_id

View 3 Replies View Related

Modules & VBA :: How To Insert Data Recordset Into Table

Jun 4, 2013

I`m currently having the problem to export data from an SQL server into a table. I managed to open a recordset but I`m incapable of adding the recordset to an existing table. I found similar threads but I am still not able to generate functioning code.

Code:
Function fDAOServerRecordset()
Dim db As DAO.Database
Dim dblcl As DAO.Database
Dim rssql As DAO.Recordset

[code]....

View 2 Replies View Related

Modules & VBA :: Delete And Insert Data From A Table In One Routine

Oct 10, 2013

Access 2010. Can vba code be written to delete and insert data from a table in one routine.

Something like Delete * Insert into select from where order by....

I tried it with a query but have to write two.

View 1 Replies View Related

Modules & VBA :: Insert Unbound Field Values Into A Table?

Mar 11, 2015

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

View 2 Replies View Related

Modules & VBA :: INSERT ADO Recordset Into Current Database Table

Apr 8, 2015

Code:
Function Write_rstADO_to_CurrdB_Table()
'Assumes you have already setup a DSN to your Server
'Assumes YOURDESTINATIONTABLE is the same structure as your SERVER.TABLE
Dim cnnADO As ADODB.Connection
Dim wkspDAO As DAO.Workspace

[Code] ....

View 1 Replies View Related

Modules & VBA :: Insert Value Of 30 Text Boxes On A Form In A Table

Sep 30, 2013

I am working on a database tool for quality team.

I have around 30 text box on a form and trying to insert the value of those 30 text boxes in a table from vba.

Here is my code

Private Sub Submit_Click()
Dim a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, bb, cc, dd As String
Dim SQL As String
a = Month
b = Week
c = Type_of_Contact
d = Country

[Code] ....

From above code I am not able to get my working done

Can we use a variable in referring a field in insert query?

I am using variable because I am not able to write the whole code in a single line and when i am pressing enter it gives me a error.

View 4 Replies View Related

Modules & VBA :: Open Form After INSERT INTO - Refresh Data In Table

Apr 16, 2014

Is there any possibilities to open form after INSERT INTO? I think Ms Access can't fast refresh data in the table after that, so form opens up clean:/

Code:
...
strSQL = "INSERT INTO tblZlecenia (id_zlecenia_info, DataPrzyjecia) VALUES ('" & ostateczne & "', Date())"
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.OpenForm "Formularz2", WhereCondition:="ID_Zlecenia=" & ostateczne

View 5 Replies View Related

Modules & VBA :: Insert Two Values From A Form In Table And Check If They Already Exist

Jan 27, 2015

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.

View 10 Replies View Related

Modules & VBA :: Insert A Record With Selected Data Into A Temp Table

Jun 29, 2013

I am attempting to insert a record with selected data into a temp table and I am getting "Run-time error '3075': Syntax error in (comma)...". Here is the code:

Code:
Private Sub XferDataToTempTable()
Dim db As Database
Dim strSQL As String
Set db = CurrentDb

[code]...

View 7 Replies View Related

Modules & VBA :: Allow User To Select Record From Subform And Add It To Table - Insert Statement

Jun 18, 2013

I have a sub form with staff records on it within a main form. I am trying to allow the user to select a record from the sub form and add it to a table, here is my code which, to me, looks correct. However it gives me an error saying "Syntax error in INSERT INTO"

Code:
Private Sub Command3_Click()
Dim dbs As Database
Dim sqlstr As String
Set dbs = CurrentDb
Forename = Nz(Forms!frm_Capex_Submission!frm_staffSub.Form.shy_forename, "")
Surname = Nz(Forms!frm_Capex_Submission!frm_staffSub.Form.shy_surname, "")

[Code] ....

View 1 Replies View Related

Tables :: Use Insert Into Command To Insert Filepath Into Table That Adds Blank Label

Aug 28, 2014

I am at work, and I have acquired a database that prints labels. They now want the database to be coded so that after certain labels are printed the database will print a blank label. I have the code figured out as a Do While statement in order to print the blank label. The problem I am having is that I am trying to use the Insert Into command to insert the filepath into the table that adds the blank label.

|DoCmd.RunSQL "INSERT INTO Rod_tmakLabels ( Print, [Order] ) SELECT Yes AS Expr1, 'Rods Labels' AS Expr2"|

If I run the above command, it just adds the text "Rods Labels" at the end of the table. Is there anyway with the INSERT INTO command that I can insert the new label between the 2nd and 3rd row and add another row? Or is the command designed only to add a new row to the end? I haven't had any luck searching for this yet.

View 1 Replies View Related

Modules & VBA :: Why Code Will Not Move To Last Record Of Table

Aug 14, 2014

I have the following code:

techid = Forms!Main!txtCurrentUserID
Task = 2
note = "Work Instructions"
strSQL = "SELECT *"
strSQL = strSQL & "FROM [tblTracking] "
strSQL = strSQL & "WHERE ([EmpID]=" & techid & ");"
Set rs = CurrentDb.OpenRecordset(strSQL)

[code]....

For whatever reason, this code will move to the last record that was entered in YESTERDAY, but I want it to move to the last record that was entered in TODAY. If I change the code to only records that are dated today, it claims there are no records (EOF), when there clearly are. why the code will not move to the last record of the table, it is only moving to the last record that was entered yesterday.

View 2 Replies View Related

Modules & VBA :: Assign Values To A Table Through Code?

Jun 24, 2015

I have a table (tblPrinterSelection) with three fields: Autonumber, DocType, PrinterSel

There are three types of values for "DocType"; "Document", "LargeLabel", "SmallLabel"

I want to assign a "PrinterSel" to each type of "Doctype", which basically means that the user selects the type of document and then the printer in a form that has the code below and then I need the code to automatically update the table.

Code:
Dim PrintSel As String
Dim DocType As String
'Assign a value to the printer selected variable
PrintSel = Me.lblPrinterSelected.Caption
If IsNull(Me.frmDocType) Then
MsgBox "No document type selected."

[code]....

What i am looking for is code that would pick the value for "DocType" and "PrintSel" assigned here and add them to the table so that I can use that info later.

I am only looking to have three rows in that table so if the "DocType" does not exist then a new row is created but if it does, only the value of "PrintSel" is updated.

I should end up with something like this:

1 Document Epson
2 LargeLabel HP
3 SmallLabel Canon

How can I do this?

View 3 Replies View Related

Update/insert How To Determine Which In Code

Jul 13, 2005

Queries are run on a webpage:
The queries would be a little bit different – instead of just one operator, it would get all operators for each category and then either create a record in Access (if it didn’t already exist) or update a record (if it already existed). For example, the first query might get

JSMITH 22
KWALTON 33
Since these records don’t exist yet, we’d do an insert for each. If the next query (for a different entry/verify category) got

JSMITH 44
VJONES 50
we would update JSMITH (since already inserted after first query) and insert VJONES. This has to be done since not everyone works in every category. Not sure if you can import different spreadsheets into Access and have it determine automatically for each row whether to do an insert or update (of course, we can do this in code in the web page).

Can you help?

View 1 Replies View Related

Modules & VBA :: DBA Code - Identify If 2 Fields Within A Table Have Been Populated

Sep 25, 2014

trying to identify if 2 fields within a table have been populated i.e.

Check date field and restaurant field, if these fields have been populated do

this

errStr = errStr & tmpDate & ", "
Else
validStr = validStr & tmpDate & ", "

[Code]...

View 14 Replies View Related

Modules & VBA :: Add Formula To Code / Export To Excel Table

Sep 25, 2014

I have a report exporting to excel using late binding techniques. When exported into excel i have numbers for 1,2,3,4 tblPreSiteSurveys. PreSiteSurvey Stop TheClockReason entitie and I am trying to either change the numbers here casting from int to string

1 = a
2 = b

looping through the record set, Or i have a blank field in my SQL for the column "P" and adding the formular to that column, but it only goes into the first row of the record set, which is a expandable table.

On Error GoTo Command29_Click_Err
'Utilergy Master Update report
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Dim UserDate As Date

[code]...

View 12 Replies View Related

Modules & VBA :: Code To Copy Partial Data To Another Form / Table

Jul 16, 2014

I have prepared a table in a database which includes a yes no box to one of the fields.

The idea of the yes/no field is that this is recording if the record is awarded. What i would like to achieve is that if the yes no box is checked "True" i would like to be able to copy some of the data from this table into a new table and that the form associated with this table opens up to enable the user to populate the remaining fields.

I believe i need to run this as an on click event procedure but cannot identify the code to enable the data to be copied accross to the other table.

View 14 Replies View Related

Modules & VBA :: Code To Delete Table And Then Run 4 Append Queries To Refresh Data

Jun 11, 2014

I have a table called "EquipmentRequired" which is populated by 4 append queries,

5000BaseReq, 6000BaseReq, 6000IFBBReq, EquipmentReq which get some of their information by counting fields in another table but all have the same field names.

The queries contain all data that is initially used to append new records to the table and this works fine.Unless some information changes or a record is added then I would like to add a button to a form and call it "update equipment" behind which would run a vba code firstly to delete all the records in "EquipmentRequired" table then run the 4 queries without the warnings and re-populate the table.

View 9 Replies View Related

Modules & VBA :: Access 2007 / Code For Bulk Importing TXT File Into Separate Records Same Table?

Jul 9, 2014

I have 12,000 cvs that i need to get into An access database so i can start to extract email info etc. They are stored in one folder All Cvs under each of their names edc.txt (i have converted them to .txt) i want to create one table with two fields name (taken from the cv filename and contents (taken fromthe contents of the .txt file). I am using Access 2007.

View 2 Replies View Related

Modules & VBA :: Take Data From One Table And Insert Into Another Whilst Doing Calculations On Data

May 2, 2014

I am trying to use SQL to run queries in our access database in order to (hopefully) speed things up. I'm trying to create code that basically takes data from one table and inserts it into another whilst doing calculations on the data.

However I can't get past this:

Code:
Private Sub Test_Click()
Dim strSQL As String

strSQL = "CREATE TABLE [TempRedAmberGreen]" & _
"AS (SELECT " & _
"[ID_CHK] String," & _
"[Red] String," & _
"[Amber] String," & _
"[Green] String)" & _
"FROM [035 - Meter Point HH Data];"
DoCmd.RunSQL strSQL

End Sub

It keeps saying "Run-time error '3292': Syntax error in field definition.

View 4 Replies View Related

Modules & VBA :: Code To Check Contents Of A Field In A Table Where Another Field

Sep 11, 2013

I am trying create some code that checks if the contents of the status field in a table is "Authorised" where the ID = something specific for multiple records. If all records witht the specific ID are "Authorised" Then generate a new record in another table. Where to start, perhaps a Dlookup?

View 1 Replies View Related

Queries :: Access 2007 - Insert Into Table Where Source Is Another Table And Form

Feb 3, 2015

If you want to use a "DoCmd.RunSQL "INSERT INTO" command to insert data in a table and the data to insert comes from a table and a form, could this be done in one pass?

So...writing a record wit 4 values from table1 together with a additional value from a textbox in table2 as 5 values.

View 5 Replies View Related

Modules & VBA :: Insert Into Using Do While

Dec 4, 2013

I have two subforms: sf1 (Based on Table 1) and SF2 (Based on Table 2) in the first I have the fields and CODE QTY.

I need to insert into the second table, as many records as QTY. to enter a serial number for each unit of the item. For example:

TABLE 1
COD. QTY.
001 2
006 1

I must insert into Table 2
001
001
006

Dim num As Integer, contador As Integer
contador = 0
num = Forms![FacturasRec_NSF]![FacturasRec_Det_SF].Form![CANLFR].Value
Do While contador = num
Insertar
contador = contador + 1

[Code] ....

but I could not even.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved