16-bit Ccitt Crc Table
Hello Everyone,
I hope that somebody is able to help me with this issue I am having. I am trying to get a link done to an application that was written in C. They are using a TCPIP connection and have sent me code samples for some of the things they expect. My problem is I am having problems converting the C code to VB 6, if anyone is able to help I would be very grateful.
Here is the C code for a 16 bit CRC check ..
Code: static WORD g_awCrc16Table[] = { 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876, 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5, 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974, 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB, 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3, 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72, 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1, 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70, 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF, 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5, 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD, 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C, 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A, 0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9, 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78 };
//@func Calculates a 16-bit CRC value given a buffer and a seed. //@parm The buffer. //@parm The size of the buffer. //@parm The seed. //@rdesc The final CRC value. WORD JTCrc16( const BYTE *lpBuff, DWORD dwLen, WORD wSeed ) { assert( lpBuff != NULL );
// Calculate the CRC value. WORD wCrc = wSeed; for (DWORD n = 0; n < dwLen; n++) { // 1. x := <input_byte> XOR <low CRC> WORD x = (WORD) (lpBuff[n] ^ (WORD) (wCrc & 0x00ff)); // 2. x := CCITTCRC16TAB [x] x = g_awCrc16Table[x]; // 3. <low_CRC> := <low_fx> XOR <high CRC> wCrc = (WORD) (x ^ (WORD) (wCrc >> 8)); } return wCrc; }
Many thanks in advance
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
CCITT CRC Translation From C Into VB
Hello,
Can some help me with the following translation of C-code into VB.
#define POLY 0x8408 /*Polynominal*/
void main(void)
{
unsigned int crc;
crc = 0xffff;
printf("crc of 'T' is 0x%x
", bytecrc("T", &crc));
}
unsigned int bytecrc(unsigned char *bufptr, unsigned int *crcres)
{
unsigned int j,ch,Q;
ch = (unsigned int) *bufptr; /* get char to int format*/
for (j=1; j<=8; j++)
{ /* do each bit LSB first*/
Q = (*crcres & 0x0001) ^ (ch & 0x0001);
/* Q = 1 if either crcres or data least significant bits are
1, but not both */
if ( Q == 0x0001)
{ /*Q is one*/
*crcres = *crcres >> 1; /* shift right one*/
*crcres = *crcres ^ POLY; /* XOR with POLYnomial*/
}
else
*crcres = *crcres >> 1; /* just shift no XOR */
ch = ch >> 1; /* move next data into position*/
}
return *crcres;
}
Thanks.
Crc16 CCITT Calculation
hi,
this is my block padded with empty spaces to reach 256 bytes
SOH
08CrLf
WLADCrLf
TS CBC,000101CrLf
ID 133133133CrLf
SN 1003CrLf
BD 10/02/1974CrLf
SX MVBCrLf
ED 06/09/03CrLf
ET 18:40CrLf
i have to calculate crc16 ccitt for this commplete block
by using algoritham
====algoritham=====
at beginning,
CRCLSB = 0FFH(octal 377)(decimal 255)
CRCMSB = 0FFH(octal 377)(decimal 255)
then for each data byte in a block,
X=D XOR CRCMSB
x=x xor (X>>4)
CRCMSB=CRCLSB XOR(X>>3)XOR(X<<4)
CRCLSB=X XOR(X<<5)
and at end,
CRCLSB=CRCLSB XOR 0FFH
CRCMSB=CRCMSB XOR 0FFH
=============
could you please help me to write code in visual basic 6 by
using above algoritham
thanks in advance
Crc16 Ccitt Calculation
ccitt crc16 algoritham
the polynomial for this algorithm is X**16+X**12+X**5+1
D = current data byte that is input to the algorithm
CRCLSB,CRCMSB=data byte.least significant and most significant CRC accumulator
bytes
x>>n means x is shifted n bits to right or is the same as x divided by 2 to the power n
x<<n means x is shifted n bits to left or is the same as x multiplied by 2 to the power n
======================algoritham=======================================
at beginning,
CRCLSB = 0FFH(octal 377)(decimal 255)
CRCMSB = 0FFH(octal 377)(decimal 255)
then for each data byte in a block,
X=D XOR CRCMSB
x=x xor (X>>4)
CRCMSB=CRCLSB XOR(X>>3)XOR(X<<4)
CRCLSB=X XOR(X<<5)
and at end,
CRCLSB=CRCLSB XOR 0FFH
CRCMSB=CRCMSB XOR 0FFH
======================this is vb6 program for above algoritham=======================================
Public Function CRC16A(Buffer() As Byte) As Long
Dim i As Long
Dim Temp As Long
Dim crc As Long
Dim j As Integer
crc = &HFFFF&
For i = LBound(Buffer) To UBound(Buffer)
Temp = Buffer(i) * &H100&
crc = crc Xor Temp
For j = 0 To 255
If (crc And &H8000&) Then
crc = ((crc * 2) Xor &H1021&) And &HFFFF&
Else
crc = (crc * 2) And &HFFFF&
End If
Next j
Next i
CRC16A = crc And &HFFFF
End Function
Private Sub Command1_Click()
Dim aBuf() As Byte
Dim crc As Long
Dim p As String
p = Text1.Text
aBuf = StrConv(p, vbFromUnicode)
crc = CRC16A(aBuf)
Text2.Text = Hex(crc)
End Sub
===============could you help to get correct answer=====
Access97...append Records From Table Of Varying Fields Into Single-field Table
Hi all,
New to this forum, and pretty much a complete noob with VB, but I've done a few things with it in Access so I'm not tatally lost. Here's my situation: my users take in a rather large and ugly Word document from a client (essentially a print-out from a mainframe application) which contains a few key bits of information that need ultimately need to be used to place an online order at a vendor website. Since this online order can involve copying/pasting a single column of data instead of manually keying each bit in, these bits of information need to be extracted from the initial document and normalized into a single column of data for the user. On the source document, these key bits of information are on individual lines separated by commas. I've gotten far enough using import/export specs and queries to produce a table that has each bit of data in it's own field; hoever, the number of fields in this table will vary with each new client document, and not all fields in each row will have values. My need is to code a routine that will cycle through each field in this table, regardless of how many fields there are, and append the non-null values from each into a different single-field table (or single field data source) which can then be spit out to the user. What's the best way to go about this?
Regards and thanks,
Stuart
Passing Data From A Query Table To An Aggregate Table(MS Access 2000)
hello....I am currently developing an accounting system for a specific company here in the Philippines...Can anybody help me or give me a code...I have an aggregate table named AggSales to be used as a source data for my report(Crystal Report 8.5), which is a comparative Profit & Loss report of two months...Now my problem is, i want to pass data from a query table named qryGenLedger to the AggSales table by which the user will select a month and a year of their choice(Month1,Year1 and Month2, Year2)...so that the data in the AggSales will be composed only by Dates which matches the choice of the user(Month1,Year1 and Month2,Year2)...thanx...please help!!!
Passing Data From A Query Table To An Aggregate Table(MS Access 2000)
hello....I am currently developing an accounting system for a specific company here in the Philippines...Can anybody help me or give me a code...I have an aggregate table named AggSales to be used as a source data for my report(Crystal Report 8.5), which is a comparative Profit & Loss report of two months...Now my problem is, i want to pass data from a query table named qryGenLedger to the AggSales table by which the user will select a month and a year of their choice(Month1,Year1 and Month2, Year2)...so that the data in the AggSales will be composed only by Dates which matches the choice of the user(Month1,Year1 and Month2,Year2)...thanx...please help!!!
{find Field In Table A, Add Record To Table B} (beginner's Question) Help Please!
Hi everybody,
I'm new to VB and completely new to databas with VB.
I have linked tables in an ACCESS db. What I want to do is that:
1- Find X in TABLE_A FIELD_A
2- If I found it, I want to add a new line to the linked TABLE_B FIELD_B
I think it's pretty simple to do but I just really don't know how all that work.
N.B. I'm using VB6
Thank you very very much
John_john
Append Data To Access Table From External Sybase Table
Hi there,
I have created a table in MS Access using ADOX - identical structure to a table which resides on a Sybase ASE 12.x server on another machine. My goal is to copy the contents of the Sybase table into the MS Access table on my PC. I have been trying to do this for two days now and can't figure it out.
I am using ADO to establish connection to the Sybase database. I can read the table I need, populate a datagrid with it, etc. But I don't know how to copy its contents to my access database.
I have tried the code below to no avail. Any suggestiong would be appreciated. Thanks in advance.
' Definitions
Dim ConnString, strSQL As String
Dim rprobDBConnect As New ADODB.Connection
' Close the remote connection if it's already open
If rprobDBConnect.State = adStateOpen Then
rprobDBConnect.Close
End If
' Setup remote connection parameters
ConnString = "DSN=MYSYB1; Uid=sa; Pwd=blah"
rprobDBConnect.CursorLocation = adUseServer
rprobDBConnect.Open ConnString
strSQL = "insert INTO prob IN 'c:probdb.mdb' select * FROM prob"
rprobDBConnect.Execute strSQL
End Sub
Add New Record In 1st Table That Auto-adds A Masked Prim.key In A 2nd Table - How?
Sorry if this is a beginner question but I cant seem to figure it out...
I am designing a system for a Construction company.
So far, I have a database with 2 tables, CUSTOMER and TASK.
I also have 2 forms created within VB, one for the Customer and one for the Task.
Customer is laid out like this (the table and on the VB form):
CustomerID
CustomerName
CustomerAddress
TaskID* (Foreign Key from Task)
The basis of the system so far is, when a new customer is added to the CUSTOMER table, it automatically means they want a TASK done.
Therefore, When I press the Add Record button on the VB Customer form, I want it to automatically add a new record to CUSTOMER, but I also want it to add a new record to the TASK table...
So far, I have been able to get it to add a new record to Customer, and also create a new record in Task at the same time - but I can't save it because it always creates the new record in Task as a BLANK record and as TASKID is a key field Blank is not allowed!!!!
I would really like it if I could autogenerate the key field TASKID using a pre-defined Format or Input Mask (eg. TASK_ _ _ is displayed and the user enters 001, 050, 150 or whatever on the lines provided, or TASK--- where the user enters numbers to replace the dashes).
I know you can do this by using either the Format or Input Mask property (I cant remember which) on a text field in MS Access - but again how do you enforce this within VB?
Hope thats not too confusing
Thanks
: Export Data From Access Table To SQL SERVER Table Programatically
Dear All,
I have a table in Access. I want to export the data from that table's fields into one field of SQL SERVER database table. for eaxmple.
Let I have a table named A in access. Table A has 5 fields. Also i have a table in SQL SQRVER.Let that table name is B. I want to export data from Access table A fileds into one field of SqlServer table B.
Can you help me plz.
(RESOLVED!!)Need Help With Code For Checking If Data In Temp Table Is In Another Table
Hi all,
I have a code that will write my data from a tempimport table to a orderstable. Then deletes the temptable. What I need help with is how to check a value in my temptable before writing it to my orderstable. Below is the code I have so far and it works great but doesnt check for duplicate data before writing.
I have looked at alot of differnt codes here and just can not seem to get a code to work correctly.
I am using VB6 and the tables are in a SQL 2000 server
Code:Private Sub cmdImport_Click()
Dim rst As ADODB.Recordset
Dim xrst As ADODB.Recordset
Set xrst = GetRecordSet("select * from tempimport")
Set rst = GetRecordSet("orderstable")
Do While Not xrst.EOF
With rst
.AddNew
!ponumber = xrst!ponumber
!sfname = xrst!sfname
!slname = xrst!slname
!pfname = xrst!pfname
!plname = xrst!plname
!phone = xrst!phone
!streetaddress = xrst!streetaddress
!aptnumber = xrst!aptnumber
!city = xrst!city
!State = xrst!State
!zipcode = xrst!zipcode
!student = xrst!student
!studentpassword = xrst!studentpassword
!Parent = xrst!Parent
!parentpassword = xrst!parentpassword
!isp = xrst!isp
!isppassword = xrst!isppassword
.Update
End With
xrst.MoveNext
Loop
MsgBox ("Import Finished")
GetRecordSet ("delete tempimport")
End Sub
Code:Function GetRecordSet(ByVal SQLString As String) As ADODB.Recordset
Dim myConnection As New ADODB.Connection
Dim myRecordSet As New ADODB.Recordset
'assign connectionString
myConnection.ConnectionString = ODBCString
'open SQL database
myConnection.Open
'set CursorLocation
myRecordSet.CursorLocation = adUseClient
'get recordset
myRecordSet.Open SQLString, myConnection, adOpenDynamic, adLockOptimistic
'return adodb.recordset
Set GetRecordSet = myRecordSet
End Function
Thanks
Clark
Edited by - clark on 2/15/2005 9:50:20 AM
Access - Linking Table : External Table Is Not In The Expected Format
I have a bunch of functions that dynamically link some tables from a third party legacy system into access so that users can create queries and link to excel, etc. easily.
There was a new release of the legacy system recently and then one table stopped linking with the error "external table is not in the expected format"
I'm using access 2000 and the legacy system uses dbf and idx extensions. the file that I'm now having problems with has aquired a new file with the same name but an extension of fpt. I think this is some sort of text or memo file but not 100% on this.
I've tried opening it in Excel and Access manually without success yet the third party system continues to function so the file isn't corrupt.
Anyway can anyone help with linking this table?
----------------------------------------------------------------------------
Dan Bayley
Affordable website design UK
Free Google & Yahoo sitemap generator
Find ALL Access Databases That Have A Linked Table To My Database Table
I have an uncountable amount of links to a highly used table out there on my network. It would take an unthinkable amount of time to track down all links.
Is anyone aware of a way to determine the names or locations of databases that contain a linked table to my table which is being linked to?
I hope this question makes sense. Let me try a very general explanation below in addition.
Tables X, Y, Z... are all linked tables in databases X, Y, Z... to a table T in database T. Is there anyway to find X, Y, Z...?
Thank very much for any info, I am glad to have found VBcity!
Travis
Help : Copying Recordset FROM Foxpro Table And Adding Into Access Table?
Hi All.
i have a problem, and need some ideas or suggestions or solutions.
i have a DBF table (visual Foxpro) which has 100.000 records.., and i want to copy maybe about half or maybe all of the records into an access table which filtered with some conditions (query).
right now, i'm using manual copy (looping each records from the DBF table) and then make addnew-update to the access table.
and yes it very slow..
my question is, is there another way which can reduce the time when copying them???
thank's alot in advance.
Retrieving Table Contents Based On Query Results From Another Table
I'm wondering if it's possible to merge two queries together to give me some records.
What I have is a History table. It contains:
History_ID (pk)
Luser_ID (fk)
Track_ID (fk)
History_Date (text)
So whenever someone plays a song, I..well...I add a record. I don't want to duplicate the track info...'cause there's a lot. I will if I have to, but I'd rather take the hard route with less data storage.
My Track table has: (condensed slightly)
Luser_ID (fk)
Artist_ID (fk)
Album_ID (fk)
Track_ID (pk)
Track_Name (text)
...blah blah blah
I have Luser, Artist, and Album tables that have the Key and a _Name text field.
My query to retrieve all the tracks for a particular user is:
Code:SELECT Track.*,Artist.Artist_Name,Album.Album_Name From Track,Artist,Album WHERE Track.Luser_ID=1 AND Artist.Artist_ID = Track.Artist_ID AND Album.Album_ID = Track.Album_ID ORDER BY Artist.Artist_Name,Album.Album_Name,Track.Track_CDTrack
As you can see it gets the text for the Artist and Album from the other tables.
To get the Track ID's from the History table...well that's too easy to post. What I need to do is get the same info I'm getting from the query above, but for all the tracks listed in the History table, with a primary order of History_Date, followed by the other three.
Before I started coding, I tried to think it through. Before I passed out from the effort, the only idea I had was to get all the track ID's from the History table for the user, say the query result looks like:
Track_ID........History_Date (not shown)
1
3
4
2
6
3
1
(Note duplicates)
Then loop through this recordset and get the track info with a similar query as the first above. I consider this route as a bad idea, so I'm trying to think of how I can inject the History table into the above query. I considered adding something like WHERE Track.Track_ID IN (SELECT Track_ID [from history table for user]), but:
What about the duplicates? Will Access give me the info for every record, even if it's duped?
How would I get History.History_Date in my records?
Or
Should I just duplicate the Artist and Album fields from the Track table to the History table, and just change the above query to reflect those instead? I'd then be storing two more fields..but that's ok with me, I reckon.
Or
Since a majority of the poeple looking at this post probably have superior database knowledge than myself, I am open to radical, deviant, or any other suggestions I can not think of.
I'm attaching a sample database for your convienence. Access 2000. Thanks if you can help!
Edited by - Blackened on 6/26/2005 7:44:55 PM
Editing Linked Table Locations In MSysObject Table
I have a db with many linked tables and I have to move where the linked tables are coming from. I can use the linked table manager, but I was hoping to open MSysObject and do a "find and replace".
Is this dangerous (assuming no forms/tables/queries are open)?
What if a form/table/query is open that gets its data from one of the tables who's linked source I am changing?
Any other words of wisdom about editing system tables directly?
Using A Data Searched From One Table As A Criteria To Search Another Table
I have three tables in an access database, Artist, Product and Client. And, I need to use Artist's medium in order to display Client's data into a dataset. The Product table contains both the ArtistID and the ClientID...
I tried doing this by making a combo box and then set its datasource and datamember properties, so that when I search using Artist's medium, all the ArtistID data would contain in that combo box... However, I cannot extract the information from the combo box to a variable, assuming because it is just a reference to the database.
Here's what i tried:
Dim ArtistID, current As Short
for current = 1 to cboArtistID.Items.Count
ArtistID = cboArtistID.Items.Item(0)
next
There's more to the code, but inside the for loop is the problem..
If anyone can give me some tips to solve this as soon as possible, I would be greatly appreciated.
Thank you,
Win
Update An SQL Server Table With Values From An MS ACCESS Table
Hi everyone in the forum. I would like to create a VB script which updates a table in an SQL Server with values from a table from my local MS ACCESS. It would be very helpful if anyone could answer how to do that.
Pleeeeeeeeeeeease !!!
PS. I 'm sorry if a thread like that already exists and i didn't see it.
Update Records In Table 1 With Existing Record In Other Table
hi,
can somebody help me on how I can resolve my problem..here's my code first thing of all...
VB Code:
Dim rsdelSet rsdel = New ADODB.RecordsetDim rsupdSet rsupd = New ADODB.Recordset rsdel.Open "Select * from tblTrackOrder Where RawID Like '" & lblRawID & "'", goConn, adOpenDynamic, adLockOptimistic, adCmdText If rsdel.RecordCount <> 0 Then While Not rsdel.EOF rsdel.Delete rsdel.MoveNext Wend End If rsdel.Close rsupd.Open "Select * from tblContacts Where ContactID Like '" & SupplierID.Caption & "'", goConn, adOpenDynamic, adLockOptimistic, adCmdText If rsupd.RecordCount <> 0 Then rsupd.Fields("CRequest") = "N" rsupd.Update rsupd.Close Else rsupd.Close End If
in my table tblTrackOrder, I deleted a record that has been processed...
let say the remaining records in my tblTrackOrder are:
ID NAME
1 Robee
3 Wendy
now, I have to equate these records to my other table called tblContacts...and in my table tblContacts my records are:
ID NAME CRequest
1 Robee Y
2 Dundee Y
3 Wendy Y
4 Plagie Y
in tblTrackOrder I only have 2 records..now I want these 2 records to be the look up so I can edit the records at tblContacts...
i want the output to be like this:
ID NAME CRequest
1 Robee Y
2 Dundee N
3 Wendy Y
4 Plagie N
when a record exist in the tblTrackOrder, it's corresponding record in the tblContact should have a Y value in CRequest field...but when a record is not existing in the tblTrackOrder it's CRequest field value should be N...I hope I've shown enough on how I want my system to work..im having difficult time thinking..i hope somebody could help me out..many thanks
SQL Alter Table (add Columns In Middle Of Table Via Script)
Lets say u have a typical SQL alter table statement like:
ALTER TABLE dbo.tbl_beneficiary_profile
ADD
unemp_upto6mon_less25_val int NULL,
unemp_upto6mon_over25_val int NULL ,
sec_public_adm_def_val int NULL ,
sec_non_specific_val int NULL
GO
Basic stuff - but what if u need to update the database in script and - unfortunately, u also need the fields to appear "not at the end of the table" - as per the default when adding fields.
any ideas, i'm thinking surely one does not have to
.1. Create temp table
.2. backup data into temp
.3. Drop main table
.4. Recreate main from scratch
.5. Bring back in data from temp
.6. drop temp table
Hell of a long way for a shortcut
Cheers
W
How To Delete Records In One Table Based On List In Second Table
Hi,
I have 2 tables
tbl_Docs with Fields:
- ID1 (Autonumber)
- DocRef (Integer)
- Others (Text)
tbl_DeleteList with fields
- ID2 (Autonumber)
- DocToDelete (Integer)
I want to write a query to delete those records in tbl_Docs where the DocRef matches the list in tbl_DeleteList (field DocToDelete)
I know how to do the simple delete for a single record
CODE
DELETE tbl_docs.* FROM tbl_docs WHERE (((tbl_docs.DocRef)=2))
RESOLVED!!! Help - Access Data From One Table And Saves It To Another Table
okay, here i am again...
i have information saved in Table1, now when i do editing or update with these data, i have to save these changes in Table2.
basing from previous codes and same interface i used with the payroll project (had combobox for the student id and upon clicking so, needed data will be displayed on the textbox controls)... here's what i did:
i put these two queries at the combo click event:
Code:
sql = "SELECT * FROM Table1 WHERE studeid =" & cmbid.Text & " "
If rsStudeData.State = 1 Then rsStudeData.Close
rsStudeData.Open sql, acadConnection, 1, 2
Call StudeData ' function for displaying data on the textboxes
Exit Sub
sql2 = "SELECT MAX(acadyear) As maxacad_year From Table2"
If rsAcad.State = 1 Then rsAcad.Close
rsAcad.Open sql2, acadConnection, adOpenDynamic, adLockOptimistic
txtacadyear.Text = rsAcad("maxacad_year") 'this textbox's visible property was set to false since it only serves as a container with my acadyear criteria in the update query
Exit Sub
End Sub
then in my update command, i created this update query... with two criteria (must update data bearing the specified student id and current year)
Code:sql1 = UPDATE Table2 SET field1 = '"& txtstude(0).Text & "', field2 = '" & txtstude(1).Text & "' field3 = '" & txtstude(2).Text & "', Field4= '" & txtstude(3).Text & "', field5='" & txtstude(4).Text & "', field6 = '" & txtstude(5).Text & "', field7='" & txtstude(6).Text & "' WHERE studeid = " & cmbid.Text & " AND acadyear = #" & Format(CDate(txtacadyear.Text), "yyyy") & "#"
acadConnection.Execute sql1
this however, had a prob with it... type mismatch - the debugger highlights whole sql
i suspect it has to be my query for the latest date, i tried setting the txtacadyear's property to visible and found out, no date is displayed - meaning my query for the latest academic year didn't work out???...
any idea? tnx...
everything started out from nothing... everyone started out knowing nothing...
Edited by - newbie2005 on 3/1/2005 9:18:08 PM
Multiple Datagrid Table Styles For The Same Data Table
Hi,
I like to generate multiple table styles for a datagrid for the SAME TABLE at design time - not dynamically-. That is, I like to see different columns of the same table at different operation modes. I have generated different table styles with the selection and formatting of my choice at design time but I can not figure out how the display one of these styles programmatically.
How can I switch from one table style to the other in the program?
Thanks in advance....
Create View From Table With 2 Foreignkey And 1 Basicdata Table
Hi, plz help..
I have a question about database design
situation:
I have 2 tables customer and paymentTerm, customer table having 2
foreign key to paymentterm table.
tblCustomer
customerID (primary key)
prsPaymentTermID (foreign key to tbl PaymentTerm)
recPaymentTermID (foreign key to tbl PaymentTerm)
tblPaymentTerm
ID (primary key)
Description
Question:
how to create a view from those tables with field like this
targetview
CustomerID
prsPaymentTermID
prsPaymentTermDesc (description from tbl paymentTerm)
recPaymentTermID
recPaymentTermDesc (description from tbl paymentTerm)
i'm using SQL Server 7
any help is appreciate, thanks in advance
Edited by - yean on 9/14/2004 1:03:20 AM
How To Write The Backup/copying Process From One Table To Another New Table?
2. Sharing file during Physical Inventory Count :
Server
more than three client computer sharing the PI.exe file in server
Clients connect to the PI.exe in server by clicking on the shortcut of PI.exe from their computer
3. PI.mdb database file backup ( tag_master ) :
Problem in backup:
* When backup the whole "PI.mdb" database at server site, some user may lock the "PI.mdb" database
at their client computer, eventhough they have already log out from PI system.
* So, lot of data loss after backup . Example, report show 100 item(tag) have been entered before backup,
but, report show only 50 item after backup.
* So, every hours, all the users must restart their client computer before backup activities carried out at
server. It would be really terrible. Because the backup need to be done every hour in one whole day
To solve this problem:
* User do not need to restart their computer or logout from PI system. They just need to stop the
the data entry and saving activities only.
* Admin just need to inform users stop the data entry and saving activities, and click on the PI system
to backup automatically. But this time, we want to backup only the tag_master table instead of the
full PI.mdb database. The concept is just the same as when user key in qty and click "save" to update
tag_master database
tag_master table
The backup process is:
* At the first time, Backup_1 and Backup_2 table are blank
* After 1 hour, copy all the contents in tag_master table into Backup_1
table
( First hour backup ) * After second hour, copy all the contents in Backup_1 table into Backup_2
Backup_1 table table, then clear all the contents in Backup_1. After that
copy all the contents in tag_master table into Backup_1
This is to ensure during the copy processing from tag_master table
to Backup_1, the Backup_1 table will not loss
* So, at second hour, we have first hour backup in Backup_2 table and
second hour backup in Backup_1 table
* At third hour, similarly, clear the contents in Backup_2 table,
copy all the contents in Backup_1 table into Backup_2 table, then
Backup_2 table (Second hour backup) clear the contents in Backup_1 and copy all the contents from
tag_master table into Backup_1
* So, at third hour, we have second hour backup in Backup_2 table and
third hour backup in Backup_1 table.
The programming logic for backup on every hour:
* Clear Backup_2 table
* Copy the contents in Backup_1 table into Backup_2 table
* Clear the Backup_1 table
* Copy the contents in tag_master table into Backup_1 table
Problems:
How to write the backup/copying process from one table to another new table?
How to delete all the contents in 1 table?
Please help me if you know how is the backup process coding.
Do you know which reference book/website having this type of backup process procedure, If yes, please inform me.
If you have better idea on this backup problem, please recommend me.
Thanks for your helping, If you do not have any ideas on this problem, I also want to say thanks to you
I am very sorry for any disturb and incovenience caused.
Use VB To Append Records To An Linked Table From An Access Table
HELP! Sometimes this statement inserts records and sometimes it doesn't. Any ideas?
Select_Statement = "INSERT INTO OECSHFIL_SQL ( ... ) SELECT ... FROM PrepayRecs"
cnnAccess.Execute Select_Statement, TotalRecsAfter, adCmdText
Using ADO data control with Access2000 database. OECSHFIL is a linked Btrieve table and PrePayRecs is an Access 2000 table.
Word 97: How To Insert A Table Into An Existing Table Cell
Does anyone know how I can insert a New Table into a cell of another table?
In Word 2000, I can issue the following code when I am within a cell of a table and the table gets inserted correctly:
Dim rRange As Range, myTable As Table
With Selection
Set rRange = .Range
Set myTable = rRange.Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=4)
End With
However, in Word97, I am not able to do this. I get an error telling me that a table already exists. Has anyone had any success with being able to insert a new table into a cell of an existing table without doing a lot of cell/row inserts and cell merges?
Customer Master Table/Order Child Table
Hi all
I m very new toVB6 Database Programming . can you please help me
CustID primary Key in Customer Table
CustID Foreign key in Order Table
What i want to do is , i want a master Detail form in detail i could see the orders of each customer.
thanks in Advance
How To Insert Table Into A Cell Of Another Table Using Word Object
hi friends,
i have inserted a table into word do using word object through VB
wddoc.tables.add selection.range, 2, 4
now i wanto to insert a table into the cell of the table created.
can u help me how to do that
i have tried like this
wddoc.tables(1).cell(1,1).range.tables.add selection.range,2,4
but i am getting an error saying that table already exists in that location,
PLEASE HELP ME OUT!!!!!
thanx
Create New Dbase 5 Table From Existing Access Table Using DAO/SQL
I am writing an app in VB 6 where I need to export multiple tables from Access (97) format to Dbase 5. What I need is the syntax for a CREATE TABLE SQL statement; specifically, what the names of the dbase data types are for the Microsoft dBase 5 ODBC driver, and how to set field sizes, decimal point format, etc. I would prefer NOT to pre-create dbase tables, as the application is going on portable computers and I want to minimize the size of the installation package.
Thanks for your help.
Bill Frisbie
Rovenet.com
bfrisbie@rovenet.com
(631) 287-3270 x 203
How To Insert Table Into A Table Cell Of Word
hi friends,
i am creating a word doc from VB and then i want to insert tables into it. i am inserting table in the following manner
wdapp.ActiveDocument.Tables.Add selection.range, 4, 1
wdapp.ActiveDocument.Tables.Add selection.range, 2, 2
but it is able to create the first table but not the second table. it is giving a error message saying that table already present in the location.
can u tell me how to insert 2 or more tables into the word doc through coding
thanx,
Help! Truncate Table - Invalid Table Name Error
Hi,
I'm trying to truncate tables in Oracle using ADO. I'm passing the table name into the sub, but keep getting "invalid table name" error (#903). I think it has something to do with the quotes that end up around the table name and this is DDL???? I can't get it to be a string without the quotes....if that makes sense. I've tried replace, putting single quotes inside the double....and hours of Web digging.
Anyway, can anyone help me? Here's the code:
The call to the sub:
If dev Then
truncate_table ("MIAPJP.IM_HEADER")
and the sub:
Sub truncate_table(table_name As String)
On Error GoTo err_hand
Dim truncate_table As ADODB.Command
Dim table_name_parm As ADODB.Parameter
Set truncate_table = New ADODB.Command
With truncate_table
.ActiveConnection = rtkprd
.CommandType = adCmdText
.CommandText = "truncate table ?"
Set table_name_parm = .CreateParameter("table_name", adVarChar, adParamInput, 50, table_name)
.Parameters.Append table_name_parm
.Execute
End With
err_hand:
Err.Raise Err.Number, , Err.Description & vbCrLf & "Error truncating tables."
Exit Sub
End Sub
Ohpleaseohpleaseohplease....
Thanks in advance!
Pat
Error Opening Table After Table Creation
I'm converting some DAO code to ADO but I've run into a problem. In the sample code below, an error (-2147217865 The Microsoft Jet database engine cannot find the input table or query 'SAK_FIELDS'. Make sure it exists and that its name is spelled correctly.) is generated at the open for the rsFields recordset. If you wait long enough and re-process the open it will run fine. This is a simplification of the actual code I'm working on. I need to be able to open tables immediately after creating them so that they can be loaded and used in subsequent table creations. Have you got any suggestions for avoiding this problem.
Code:
Dim dbKey As New ADODB.Connection
Dim dbKeyCat As New ADOX.Catalog
Dim tdWork As New ADOX.Table
Dim Idx1 As New ADOX.Index
Dim cTableName As String, cFieldName As String
Dim rsFields As New ADODB.Recordset
On Error GoTo OpdbErr
dbKeyCat.Create "provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:TempTestADO.MDB"
dbKey.Open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:TempTestADO.MDB"
cTableName = "SAK_FIELDS"
Set tdWork.ParentCatalog = dbKeyCat
With tdWork
.Name = cTableName
cFieldName = "FIELD_ID"
.Columns.Append cFieldName, adInteger
.Columns(cFieldName).Properties(0).Value = True
cFieldName = "PRIORITY"
.Columns.Append cFieldName, adInteger
.Columns(cFieldName).Properties(1) = 0
cFieldName = "NAME"
.Columns.Append cFieldName, adVarWChar, 60
.Columns(cFieldName).Properties(13) = True
' Indexes
.Keys.Append "ID", adKeyPrimary, "FIELD_ID"
.Keys.Append "NAME", adKeyUnique, "NAME"
End With
dbKeyCat.Tables.Append tdWork
Set Idx1 = Nothing
Set tdWork = Nothing
rsFields.CursorLocation = adUseServer
rsFields.Open cTableName, dbKey, adOpenKeyset, adLockOptimistic, adCmdTableDirect ' adCmdTable
rsFields.Close
dbKey.Close
Set dbKey = Nothing
Set dbKeyCat = Nothing
Exit Sub
OpdbErr:
MsgBox ("Hey pal, you got this error:" & Err.Number & " " & Err.Description)
On Error GoTo 0
Exit Sub
Bulk Insert: Copy Table To Table?
I have a client that copies all data from one table to another every
week.
We use DTS at the moment, but someone said that it could be
done with T-SQL Bulk insert.
Did some reading, but I can't figure out how to use a table as input...
Info: SQL server 2000. Table size is 3 GB
It is slow, maybe Bulk is faster.
The log file growes to 6 gb.
I tried exporting to file and import using BCP, but found no performance
increase.
I searched the forum but didn't find anything on table to table copy.
/Jerry
VB6 - Copy A Table's Columns To Another Table Within The Same Database
Hi everyone,
I have two access tables "TableA" and "TableB" TableA has 9 columns and TableB has 4 columns. I created a new table "TableC" with 5 columns. I want to copy 3 columns from TableA(with its data) to TableC and Copy one column from TableB to TableC . I added a new column to TableC and this column will only contain the indexes of a column from TableA. After copying those columns, I want to delete the copied columns from TableA and TableB. My final objective is to make two of the fields(columns) in TableC a foreign key to TableA.
All of these tables reside within the same MS Access database.
What is my best code approach to accomplish this objective?
Thanks.
tgif
P.S. I am developing in VB6.0 environment.
Edit by loquin: moved to the classic VB database forum.
Create New Table And Insert Values In It From Another Table
Hi all
What I wanna do is create new table and insert values in it from another table based on query, but I always get error
Error = 'Runtime error 3704: - Operation not allowed when the object is closed'
here is code
Code:
Private Sub mnuZadnji_kontakt_s_klijentom_Click()
Dim MyConn As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
Dim MyRecSet1 As ADODB.Recordset
Dim ime As String
Dim prezime As String
Dim datum As String
Dim gsm As String
Dim telefon As String
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & rut & "';"
MyConn.Open
MyConn.Execute "CREATE TABLE zadnji_kontakt_klijent (Datum TEXT (50), Ime TEXT (50),Prezime TEXT (50), GSM TEXT (50), Telefon TEXT (50))"
Set MyRecSet1 = MyConn.Execute("SELECT * FROM klijenti order by prezime desc")
Do Until MyRecSet1.EOF
ime = "" & MyRecSet1.Fields.Item("ime").Value
prezime = "" & MyRecSet1.Fields.Item("prezime").Value
telefon = "" & MyRecSet1.Fields.Item("telefon").Value
gsm = "" & MyRecSet1.Fields.Item("gsm").Value
datum = "" & MyRecSet1.Fields.Item("dat_uklj").Value
Set MyRecSet1 = MyConn.Execute("INSERT INTO zadnji_kontakt_klijent (Datum, Ime, Prezime, GSM, telefon) Values ('" & datum & "', '" & ime & "', '" & prezime & "', '" & gsm & "', '" & telefon & "')")
MyRecSet1.MoveNext
Loop
MyConn.Close
End Sub
How Do I Match The Primary Keys Of A Table With Another Table?
hi, all.. whats the fastest way of setting a relation btw 2 tables, in order to know that which primary key(s) is the odd one out in each of the individual table?
Eg. my main table - A contains a primary field called sno with 10 records, table B also contains a primary field called sno with 9 records, so how do i actually set a relation and match the corresponding snos btw the 2 tables and find the odd one out in table B ??? Can someone show me an example on this??
I Need To Move A Record From One Table In A Database To Another Table.
I Have a Program i'm writing for my college course
I need help Moving one record from one table in the database to another
I'm Using a ADO Control in the Program.
PLEASE HELP!!!
THANKS,
LYLE,
{ Computers are like air conditioners, They work fine until you start opening windows }
Make Table To A Variable Destination Table Name
I am trying to create a unique destination table name when I close out the transactions for the day. I have done a maketable query with all the master table's records, but the Query requires a static Destination Table name and a static Destination DB name. Is there a way to substitute a variable name for both of these names with Classic VB?
I am using VB 6.3 from within Access. Does anyone have a solution that they have found?
Updating A SQL Server Table From An Access Table ...
I have an Access database table and a SQL Server 2000 table.
They are both called the same name.
The structure of the fields, and the field names themselves, are exactly the same.
Is there a neat way of inserting records into the SQL server table as I read thru the records I have returned from the Access table ?
I can't do a complete table to table move as I am checking in the first instance for an "Uploaded" flag that is set to "N" as opposed to a "Y" in the Access tables records.
I'm guessing the way I have in mind of doing this is not half as tidy as someone might soon suggest .... fingers crossed
Filling Up Table Field In Table Array
I declared array as Table_arr(10,10)
i want to fill up the field which i have in the table. Example table name is Price. How do i fillup this field in table_arr.
anyone can help me in this regards
thanx in advance
by
yasi
Create Table With Same Table Structure In Different Database
hi to all
i have a prob...
i want to create a table with same data structure of different table but table is in another Database... i am usin ADOs in VB
and the Database is MS ACCESS
/...
plz reply asop... as i require it urgently
waiting 4 your response
Jatin
How To Insert Table Into A Table Cell Of Word
hi friends
i want to add a table inside a table cell, i am using the following code to achieve this, but i am getting and error saying that the table is already located in the location. i think there is some problem with the range.
wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range.Tables.Add wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range, 2, 1
thanx,
|