Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 284937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:30:04+00:00 2026-05-12T05:30:04+00:00

Using VB 6 and Access Database My query. Creating a table sql4 = CREATE

  • 0

Using VB 6 and Access Database

My query.

Creating a table

sql4 = "CREATE TABLE tmp_MOI (RECORDNO varchar(20), PERSONID varchar(20), EmpName varchar(50), TitleName varchar(50), Titlecode varchar(50), Department varchar(50), Nation varchar(50), CardEventDate varchar(50), Intime varchar(20), Outtime varchar(20), PrevDate varchar(50), PrevOut varchar(20))"
If rstmpCardEvent1.State = 1 Then rstmpCardEvent1.Close
rstmpCardEvent1.Open sql4, Cn, adOpenStatic, adLockOptimistic

Selecting a fields from the table and saved into the recordset

sql9 = "SELECT RECORDNO, PERSONID, EMPNAME, TITLENAME, TITLECODE, DEPARTMENT, NATION, CARDEVENTDATE, INTIME, OUTTIME, (select TOP 1 F1.CARDEVENTDATE  from tmp_cardevent as F1 where F1.RECORDNO < F2.RECORDNO  AND F1.PERSONID = F2.PERSONID order by F1.RECORDNO  DESC, F1.PERSONID DESC) AS PrevDate, (select TOP 1 F1.OUTTIME  from tmp_cardevent as F1 where F1.RECORDNO < F2.RECORDNO  AND F1.PERSONID = F2.PERSONID order by F1.RECORDNO  DESC, F1.PERSONID DESC) AS PrevOut FROM tmp_cardevent  AS F2 ORDER BY F2.NATION, F2.TITLECODE, F2.PERSONID, F2.CARDEVENTDATE"
If rsCardEvent1.State = 1 Then rsCardEvent1.Close
rsCardEvent1.Open sql9, Cn, adOpenStatic, adLockOptimistic
cmdcardevent1.CommandText = sql9
Set rsCardEvent1 = cmdcardevent1.Execute

Inserting a fields into the table

While Not rsCardEvent1.EOF

sql10 = "INSERT INTO tmp_MOI values('" & rsCardEvent1(0).Value & "' , '" & rsCardEvent1(1).Value & "', '" & rsCardEvent1(2).Value & "', '" & rsCardEvent1(3).Value & "', '" & rsCardEvent1(4).Value & "', '" & rsCardEvent1(5).Value & "', '" & rsCardEvent1(6).Value & "', '" & StringToDate(rsCardEvent1.Fields(7).Value) & "', '" & rsCardEvent1.Fields(8).Value & "', '" & rsCardEvent1.Fields(9).Value & "', '" & StringToDate(rsCardEvent1.Fields(10).Value) & "', '" & StringToTim(rsCardEvent1(11).Value) & "') ORDER BY '" & rsCardEvent1(4).Value & "'"
If rstmpCardEvent1.State = 1 Then rstmpCardEvent1.Close
rstmpCardEvent1.Open sql10, Cn, adOpenStatic, adLockOptimistic
rsCardEvent1.MoveNext

Wend

When I check this query in the access database – It showing correctly, order by nation, titlecode like 001, 002, 003 so on…, personid, cardeventdate

Nation, personid, cardeventdate is showing correctly in the tmp_MOI table

But am not getting the title code properly in the tmp_MOI Table, it showing titlecode in the tmp_MOI table like 001, 002, 001, 003, 002 so on…

What wrong in my code, is any problem in my code?

Need query or code Help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:30:04+00:00Added an answer on May 12, 2026 at 5:30 am

    First – I am not sure why you would have

    ORDER BY '" & rsCardEvent1(4).Value & "'"
    

    in the Insert statement when you are inserting in a recordset loop and in so doing inserting one row at a time.

    Second – Do you have the right number of rows. Could it be that your joins are incorrect so that you are getting multiple rows for each titlecode?

    Third -if you have the right number of rows, remember that RDBMS are designed so that the order of records in a table should be independent. So, if you SELECT without an Order By clause, there is no guaranteed order for the data. Add an Order By clause when you need to view the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 202k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer "<ul><li>" + "adam, lisa, john, sarah".split(", ").join("</li><li>") + "</li></ul>" [Edit:]… May 12, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure if you need a path between every… May 12, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer The post is done asynchronously so the following statement is… May 12, 2026 at 8:19 pm

Related Questions

I'm using Entity Framework to access my MySQL database. The model was generated using
In my application I do the follwing things: Open a Access database (.mdb) using
Grasping at straws here... I work with a VB6 desktop system using several 2003-style
What is the best way to centralize and secure the connections strings used by

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.