|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Create new field
hey everybody,
can anyone please help? i have a database that a single table is imported weekly. i have a text box which a user enters a date for the report they want to see and a cmd button which creates a temp table. i have 5 fields that i am putting in the query from the imported table, they are: Account, Day, Draw, Returns, & Net. i want to create a totaly new field (with VB) to perform calculations, for example... Return % = Returns/Draw here's my code: Private Sub cmdEnter_Click() Dim db As DAO.Database Dim tdf As DAO.TableDef Dim fld As DAO.Field Dim rst As DAO.Recordset Dim strSQL As String Dim strTableName As String ' 1: Create a new temporary table strSQL = "SELECT * " & _ "INTO tblTemp " & _ "FROM " & _ txtDate.Value DoCmd.SetWarnings False DoCmd.RunSQL strSQL DoCmd.SetWarnings True ' 2: Move the top 50 into a new table and add required fields strTableName = "top50" strSQL = "SELECT TOP 50 tblTemp.Account, tblTemp.Day, tblTemp.Draw, tblTemp.Returns, tblTemp.Net " & _ "INTO " & strTableName & " " & _ "FROM tblTemp " & _ "ORDER BY tblTemp.net Desc;" DoCmd.SetWarnings False DoCmd.RunSQL strSQL DoCmd.SetWarnings True DoCmd.OpenTable "top50" End Sub i've been searching internet and looking thru books for bout a week and a half, can someone please help? thanks! |
|
#2
|
|||
|
|||
|
One easy way to get an extra column in your temp table is to add a bogus column in the SELECT INTO.
SELECT *, whatever as NewCol INTO tblTemp If you need to specify specifics of the column, like a particular varchar width or numeric type, look into the ALTER TABLE ddl sql command. You can find documentation in the Jet SQL portion of the Access online help.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Create new field |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|