Creating And Populating A Table In Access With VB Coding

May 6, 2008

I have currently been given a task to re-work some current coding within Access. This is well above my understanding of Access and was hoping to get a little assistance with some simple coding language.

The database I am manipulating has data collected from tourists about their destinations and origins.

I wish to create 2 tables based on a current table. One table will be short trips (trip length <= 150km) and the other long trips (trip length < 150kms)

I wish for these tables to be created from a table of raw data upon the click of a button (GUI interface).

If you are puzzled by my question. I'll try to make it simplier by asking:

1. what line of code will create a new table overriding old
2. what type of code is required to create this table with specific column headings?
3. How do I import information from current available tables with the condition: 'Row Y' is > X

View Replies


ADVERTISEMENT

Modules & VBA :: Creating And Populating Temporary Table From String

May 9, 2014

I'm trying to create a temp table, which is populated by a string, (taken from a recordset).

My problem is incorporating the String into the SQL statment, and making it work,

What I'm trying to do is to create a temp table, and populate it with the first record of the recordset, (which is an e-mail address).

(The recordset and the strings work fine). It's the SQL statement which doesn't work.

Here's the code I have :

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Set DBS = CurrentDb
Set RST = DBS.OpenRecordset("SELECT Contact FROM Contacts_to_be_Mailed")
Dim My_Count As Long
Dim ContactString As String

RST.MoveFirst
ContactString = RST(0)

Dim strTable As String
strTable = "TempContact"
DoCmd.RunSQL "INSERT * INTO " & strTable & " FROM ContactString "

View 1 Replies View Related

Help Creating A Populating Field.

Jul 9, 2007

A fellow employee of mine who is self taught in Microsoft Access currently has a database with a form that contains fields labeled name and address. She is trying to set it up so that when she begin to type, it will automatically look up to see if that name and address was previously entered to cut down on having to repeat it every time. She has tried the look up function with no success. She is using a single table as a base. Any assistance anyone can give us will be fantastic!! If I have posted this in the wrong forum or if this question was already answered, I could not locate it and I'm sorry if I am not following proper forum protocol.
Thanks!!

View 3 Replies View Related

New To Visual Basic Coding In Access

Mar 31, 2006

I am not new to Access, however I am just starting to get to the point where I need visual basic to complete some things I want to try. My question is, how do I code a button (or modify an existing one) in my form that will email the same output I get when I use a Print Report button. Here is what I have from my standard buttons:

Private Sub Save_Svc_Record_Click()
On Error GoTo Err_Save_Svc_Record_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Save_Svc_Record_Click:
Exit Sub

Err_Save_Svc_Record_Click:
MsgBox Err.Description
Resume Exit_Save_Svc_Record_Click

End Sub
Private Sub Prt_Svc_Record_Click()
On Error GoTo Err_Prt_Svc_Record_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection

Exit_Prt_Svc_Record_Click:
Exit Sub

Err_Prt_Svc_Record_Click:
MsgBox Err.Description
Resume Exit_Prt_Svc_Record_Click

End Sub
Private Sub Add_Svc_Record_Click()
On Error GoTo Err_Add_Svc_Record_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_Svc_Record_Click:
Exit Sub

Err_Add_Svc_Record_Click:
MsgBox Err.Description
Resume Exit_Add_Svc_Record_Click

End Sub

Thanks in advance for any help I can get.

View 1 Replies View Related

Access 2000 - Colour Coding Fields?

Jan 23, 2006

Hi, I need to colour code fields in my database based on whether the data entered is a guess, derived data or factual data...

I have no idea how to do this! Apart from create a field corresponding to each field in my database with the values 1-3 in (1 for guess, 2 for derived etc) but I'm pretty sure this will dash any hopes I have of getting normal form in my database.

Anyone know an easy way to do this? As far as I know conditional formatting won't work as it's the user that tells the database what colour code to use for each field.

Thanks very much for any help you can provide.

Cheers,

Toby

View 11 Replies View Related

Forms :: Color Coding A Box On Access Report

Jul 2, 2013

I can use Conditional Formatting on the text to color code the record data in a report.But, I want the text to be the same color.What I'm trying to do is add a Box control from the Design Tools and color code the box depending on the value of a field in the table. The box will appear next to the record.

The field is called ReminderTypeID and there can be only two values for this field - 1 or 2.If the value is 1 I want the box's BackColor to be red. Otherwise what ever color I assign it to in design view.I've tried the following in the On Current.

Code:

If Me!ReminderTypeID = 1 Then
Me.bxCode.BackColor = RGB(186, 20, 25)
End If

I get no error messages but in all records bxCode has the same color which isn't the one I'm trying to set.

View 5 Replies View Related

Coding Command Button To Add A Few New Records To A Table

Nov 2, 2006

I have 2 tables, one has a list of comments indexed by numbers.

The second table will be populated with numbers that correspond to the first table based on usage of the form that I'm about to describe.

The form contains several check boxes. Each corresponds to a comment from the first table. If 3 of the check boxes are selected when the command button is pressed, I want three separate new record entries to go into the second table and the data that I want entered is the text in the label that is next to each check box on the form. After the records are added to the table, I'd like to reset the check boxes.

I simply cannot figure out how to code the button to do this.

View 3 Replies View Related

Forms :: Coding User Login Form In ACCESS 2010

Apr 14, 2013

I have used Combo box. security_level field is the one that describes their levels and there are only two levels 1 and 2.. I have a table called User (user_ ID, User_Name, Password, Security_Level) On form there is a combo box for user name and text box for password. Two command button where one is for EXIT (Closing the application) and the second button is to run the code.

if the password in table User matches value chosen in combo box or user name and password are correct Then it should check if Security_Level of the user is equal to 1 to displays a form called Admin and when the Security_Level of the user is equal to 2 to display a form called user1.All that I want is to have a login that has two user and each user when login opens his/her own form which is different from the other user.

View 14 Replies View Related

Creating Views To A MS-Access Table

May 9, 2006

Hi all,

I write a program which is querying some data from a MS-Access database.
The problem here is, that the tablenames contain characters like "/" or "-" and I
do not want to change these names, because I think that the database
structure will be damaged.
To solve this problem I thought of creating a view to the table. I tried creating
this with a SQL statement, but that did not work.
Is there any other possibilty to create a view on a MS-Access table?

Regards,
Stefan

View 2 Replies View Related

Dynamically Creating MS Access Table

Feb 5, 2008

Hi,

I am trying to create a series of MS access tables from within a SQL 2000 DTS package. The names of the tables reflect the date range of the data within them. Creating the "Create table ddmmyy ...." statement isn't a problem (full code below), but doesn't run as it creates a Jet error - "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'. Does anyone know if what I'm trying to do is possible.

Before anyone suggests it, yes I have posted this on SQL server forums.

declare @TheName char (8)
,@Cmd char (500)

select @TheName = (select max(LastRunDate) from NSP_Analysis_Dates)

select @Cmd = 'CREATE TABLE `NSP_Analysis_' + @TheName + '` (`TYPE` VarChar (200) NULL, `VENDOR_NO` VarChar (10) NULL, `VENDOR_NAME` VarChar (50) NULL, `AMOUNT_CLAIMED` Currency NULL, `REGION` VarChar (100) NULL, `CLUSTER` VarChar (100) NULL, `PLANT_CODE` VarChar (15) NULL, `PLANT_NAME` VarChar (50) NULL, `DATE_OF_SERVICE` DateTime NULL, `STATUS` VarChar (200) NULL, `TICKET_NO` VarChar (20) NULL, `NOTES` VarChar (255) NULL, `DATE_ENTERED` DateTime NULL, `AuthorisedByName` VarChar (50) NULL)'
sp_executesql @Cmd

View 1 Replies View Related

Creating A New Access Table From A Recordset

Jul 21, 2007

I'm experimenting in MS Access VBA reading from one MS Access application to another as visible in the code below. My problem is that I'm reading a recordset from an Access file and want to take that recordset (rec) to create a table in the current databank. If I run an cmd.commandtext "make table query" it runs the query across the connection and places the table in the remote database (as expected). Can I take the recordset and create a local table using ADODB command or is there a better approach. (I should note that the remote MS Access file does not have an .mdb suffix) Thanks in advance.

Sub get_indbyind()

Dim strInputfile As String
Dim dlgOpen As FileDialog
Dim bob As String
bob = Application.CurrentDb.Name

' select connection
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = False
.Show
End With
strInputfile = dlgOpen.SelectedItems.Item(1)

' make connection
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
Dim strcnn As String
strcnn = "Provider=Microsoft.jet.OLEDB.4.0; Data Source=" & strInputfile
cnn.Open strcnn
' MsgBox "connection made"

' create recordset
Dim rec As ADODB.Recordset
Set rec = New ADODB.Recordset
rec.Open "SELECT * FROM SATransfers;", cnn

Dim n As Long
Dim i As Long

Do While Not rec.EOF
Debug.Print rec.Fields(0).Value; rec.Fields(1).Value; rec.Fields(2).Value; rec.Fields(3).Value
rec.MoveNext
Loop

' create table from connection cnn
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Dim rs As New ADODB.Recordset
cmd.ActiveConnection = cnn
cmd.CommandText = "SELECT SATransfers * INTO tmp1 FROM SATransfers;"
Set rs = cmd.Execute


cnn.Close
Set cnn = Nothing
Set cmd = Nothing
End Sub

View 2 Replies View Related

Access Not Creating A Table Of Rejected Records

Mar 6, 2008

Hi i hope someome can help. I am importing a data into a table, records are being rejected as they should due to validation rules. However access is not creating a table of rejected records. What am i doing wrong.
Thanks for any help

View 4 Replies View Related

Creating Access Table Linked To Excel File

May 22, 2013

I am trying to create an access table linked to an excel file.

The excel file has 256,000 kb, 15 columns, 6,400 rows.

When I go to CREATE, DESIGN VIEW in access and try to create the new linked access table i get this message -

"MICROSOFT ACCESS HAS ENCOUNTERED A PROBLEM AND NEEDS TO CLOSE". I click on Ok and then it says "REPAIR MY OPEN DATABASE AND RESTART MS ACCESS".

I click on OK and then save the back up file. The file disappears. I start over again and the same process starts again and again...

View 14 Replies View Related

Queries :: Access 2010 - Creating Query From Selected Table

Mar 27, 2014

I have just upgraded from Access 2003 to 2010. Now I'm trying to relearn some of the small things I used to be able to. In 2003, I could just have a table highlighted and select "Insert, Query". It would then open a query design with that table. Is this possible to do this in 2010? Or do you have to open query design then add the table manually?

View 2 Replies View Related

Populating Master Table With Info From List Table

Aug 29, 2006

I have a form that I am working on.

When you open the form, it asks for a tool # (which will be a drop-down box). There will be a command button that will bring up a sub-form. In the subform, there are 2 combo boxes. One picks the group that the tool falls under, and the other has the section of the group for the tool.

When the user picks the section, I need it to filter the questions that pertain to that section (which is listed in a list table), and pull those questions, and populate the master table with them. (i.e., Pulls "where is tool?" from tblQuestions, and puts it in the tblQuestionMaster when section is selected from combobox).
:confused:

View 1 Replies View Related

Table Not Populating

Jan 26, 2005

I created a form and in form I have created a combo box, and I can make as many selection I want through multiple box properties; however, its not populating in the table. Now if I keep select non in multiple menu I can input the value in table through that form. How can I make this field populated with more than one value.

Need help urgently. Thanks in advance :)

View 1 Replies View Related

Populating A Table?

Feb 11, 2005

I have an expression in a field on a report. I would like that calculation to populate my table. Do I ad something to the expression in that field that would tell it to take the sum of the field and place it in the table? What would the expression look like?

The report is created from the results of a data entry form.

View 1 Replies View Related

Populating Data With Asp And Access

Nov 13, 2004

Hello all.


Does anyone know of a way to populate an access database with data, specifically 1000 entries(These entries would consist of 2 fields one of which is text and other is numbers.) to a database table?


Thank you.

View 4 Replies View Related

Populating Table After Search On Another

Jan 8, 2008

Hi, Im trying to, upon the click of a forms button, search the records in one table for all records matching a certain number. I then want to update another table with all these records...but am stuck in the coding. This is what i have so far...

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblAllInfo", dbOpenDynaset)

With rs
.MoveFirst
Do Until .EOF
If .Fields(1).Value Is 1 Then

event_num = .Fields(1).Value
Sport = .Fields(2).Value
team = .Fields(3).Value
Date = .Fields(4).Value
Time = .Fields(5).Value

rs.Update

Set rs = db.OpenRecordset("tblCurrentEvent", dbOpenDynaset)
rs.AddNew
rs![Event_No] = event_num
rs![Sport] = sport
rs![Team_Player] = team
rs![Date] = Date
rs![Time] = Time
DoCmd.OpenForm "frmInfo" 'whose record source is tblCurrentEvent

But I really need to be updating the latter table within the loop but dont know how to do that without resetting the loop pointer?? Or would it be better to create a form for tblAllInfo. Any help would be appreciated! Tania smile

View 9 Replies View Related

Populating A Table With With Dates

Apr 17, 2008

I need a table that has all the year dates in a field (e.g. from 01 Jan 2008 to 31 Dec 2008)
This means some 365 records! I hardly can type them all
Wanted to know how to populate this table automatically.

Thanks

View 4 Replies View Related

Populating Fields/table

Jun 17, 2005

I have search the forum but dont seem to be able to find the solution i am looking for. I am hoping its because it has a simple solution .......

I have a database which records grant applications for the current year. What i also have is a table which stores all the grant applications from last year and i have a search form which the user can search to see if the applicant applied last year. What i want the user to be able to do is if the applicant did apply last year - to be able to double click on the particular applicant on the search form and populate the fields in the new applicant table, show on the new applicant form, and delete the applicant from last years table. This would save the user time because they would not have to retype name, address etc. Can someone please point me in the right direction? I seem to have a mental blank with this one.

View 5 Replies View Related

Populating A Query From A Table.

Oct 26, 2004

I’m looking for a formula that will take the last two digits of a “Code”, in Query, and search for the “Range”, in a Table. (Sometimes the “Range” may only have one code in it.) The value returned should of another column. (“Desc”.)

The formula should look at “Code: 123456”, in the Query, take the last to digits in the code “56” and find it in the “Range”, in the Table, returning a value of Supplies.

Query 1: Code: 123456

Table 1:

Code-------Range-------Desc.
10 ----------10------------Direct
20---------20-29--------Indirect
50---------50-59-------Supplies

Any help or guidance would be greatly appreciated.

View 11 Replies View Related

Cascading Look Up Not Populating Table

May 5, 2008

I have a form that contains two controls for determining the law that applies for specific contracts. When you select the first control, there is a drop down from which you select the country. If you select US, then the second control has a drop down with the US states available for selection. If you select Canada, then the second control lists the provinces of Canada. If you select any other country, the state box is greyed out.

At input time, this works fine, however, I am missing something to get the second control to save the data to the underlying table. I am sure it is a simple code, but I am still a novice at code and can use your help. Here is the code for the first section. I appreciate any help. The second control cboState is currently unbound and I am sure that is part of the problem but am unsure of the solution.

Private Sub cboTermsCountryLaw_AfterUpdate()
On Error Resume Next
Select Case cboTermsCountryLaw.Value
Case "United States"
CboState = Null
CboState.RowSource = "tblStates"
CboState.Enabled = True
Case "Canada"
CboState.RowSource = "tblProvince"
CboState.Enabled = True
Case Else
CboState = "N/A"
CboState.Enabled = False
End Select
End Sub

Alan

View 8 Replies View Related

Populating Spreadsheet Control In Access

Oct 22, 2005

Hi, I am new to access XP. Pls. can someone tell me how can a spreadsheet control on an access form be linked to a table for retrieving data onto it. I tried export/import with a .csv/txt file but can there be a better way? Thanks in advance.

View 4 Replies View Related

Forms :: Access Subform Not Populating

Jan 1, 2014

A subform on a main form is not populating after the user clicks on the subform and then returns to the main form and updates the field which the subform is linked to. The first time the subform populates absolutely okay; however once the user clicks on the subform and then returns to the mainform and updates the field which the subform is linked to the subform goes blank.

View 7 Replies View Related

Control Source And Populating Table???

Mar 25, 2008

Hi Guys

Im really confused on what to do

Basically I have a form, and inside that form there is the "Total Cost" field which is a field in the "tbl_Transactions" table; to display some values from a subform inside of the "Total Cost" field i changed the control source of the "Total Cost" text box to the fowllowing expression:

=[Forms]![frm_Transaction]![frm_ProductReceipt].[Form]![Cost]

But obviously because of the fact that the control source has been changed these values brought up by the expression are not put into the table so the "Total Cost" column in the transactions table (tbl_Transactions) is just blank.

Is there any way I can make it so that the values drawn up by the expression will also be entered into the " Total Cost" field in the transactions table as well as being displayed on the form?

View 2 Replies View Related







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