Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 13th, 2006, 06:26 PM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query to extract data from 2 tables of .mdb file

Hi

i m trying to extract data from two different tables in same .mdb file where two tables are: StudentProfile and Accounts
mdldb is name of module where i've connected my vb with database
srchAccounts is the form where user enters student ID to search account info of that student.
my code is as follows:

Private Sub Form_Load()
Dim a As Integer

a = Val(SrchAccounts.txtEnterID.Text)


txtID.Text = a
cmbInstall.AddItem (One)
cmbInstall.AddItem (Two)
cmbInstall.AddItem (Three)
cmbInstall.AddItem (Four)
cmbInstall.Text = Two


Dim sql As String
Dim rs As New ADODB.Recordset
'On Error GoTo err1
mdldb.dbconnect
Set rs = mdldb.conn.Execute("select sp.FirstName, sp.Course, sp.Semester, ac.TotalFee, ac.Installments, ac.AmountsPaid, ac.DateOfPay, ac.DuesRemaining, ac.DueDate from Accounts ac, StudentProfile sp where sp.StudentID = ac.StudentID and sp.StudentID= " & a & "") 'error is here is sql query, it says type mismatch in criteria expression

AccountsInfo.Show
txtStdName.Text = rs!FirstName
txtCourseName.Text = rs!Course
txtCohort.Text = rs!Semester
txtFee.Text = rs!TotalFee
cmbInstall.Text = rs!Installments
txtPaid.Text = rs!AmountsPaid
txtDateOfPay = rs!DateOfPay
txtDuesRem = rs!DuesRemaining
txtDueDate = rs!DueDate

End Sub

help me plz
Ana

Reply With Quote
  #2 (permalink)  
Old March 14th, 2006, 03:43 AM
Authorized User
 
Join Date: Mar 2006
Location: Bratislava, , Slovakia.
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are the datatypes of those fields (especially StudentID)?
Or try to use JOIN clause in SELECT.

Peko

Reply With Quote
  #3 (permalink)  
Old March 14th, 2006, 07:49 AM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi peko!

Data types of StudentID is Numeric,
i tried using INNER JOIN but now it says missing operator in the sql query. would u be able identify whats missing in this statement?

"SELECT StudentProfile.StudentID, StudentProfile.FirstName, StudentProfile.LastName, StudentProfile.Course, StudentProfile.Semester, Accounts.TotalFee, Accounts.Installments, Accounts.AmountsPaid, Accounts.DateOfPay, Accounts.DuesRemaining, Accounts.DueDate FROM StudentProfile where StudentProfile.StudentID=" & a & " INNER JOIN Accounts ON StudentProfile.StudentID=Accounts.StudentID;"

thanx Ana

Reply With Quote
  #4 (permalink)  
Old March 14th, 2006, 09:04 AM
Authorized User
 
Join Date: Mar 2006
Location: Bratislava, , Slovakia.
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Type WHERE clause after JOIN

e.g.
SELECT <fields> FROM <tables> INNER JOIN <joins> WHERE <condition>

Reply With Quote
  #5 (permalink)  
Old March 14th, 2006, 04:26 PM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peko!! i tried putting INNER JOIN before WHERE but it says 'syntax error in JOIN operation' is this format correct?

"SELECT StudentProfile.StudentID, StudentProfile.FirstName, StudentProfile.LastName, StudentProfile.Course, StudentProfile.Semester, Accounts.TotalFee, Accounts.Installments, Accounts.AmountsPaid, Accounts.DateOfPay, Accounts.DuesRemaining, Accounts.DueDate FROM StudentProfile, Accounts INNER JOIN Accounts ON StudentProfile.StudentID=Accounts.studentID where StudentProfile.StudentID=" & a & ""

Ana

Reply With Quote
  #6 (permalink)  
Old March 14th, 2006, 06:27 PM
Authorized User
 
Join Date: Mar 2006
Location: Bratislava, , Slovakia.
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Subuana
 Peko!! i tried putting INNER JOIN before WHERE but it says 'syntax error in JOIN operation' is this format correct?

"SELECT StudentProfile.StudentID, StudentProfile.FirstName, StudentProfile.LastName, StudentProfile.Course, StudentProfile.Semester, Accounts.TotalFee,  Accounts.Installments, Accounts.AmountsPaid, Accounts.DateOfPay, Accounts.DuesRemaining, Accounts.DueDate FROM StudentProfile, Accounts  INNER JOIN Accounts ON StudentProfile.StudentID=Accounts.studentID where StudentProfile.StudentID=" & a & ""

Ana

Kick item accentuated with bold and try again, or send me please, fields description of these tables (I try query syntax home)

Peko

Reply With Quote
  #7 (permalink)  
Old March 16th, 2006, 03:37 PM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peko!!
Thankx ! it worked after kicking the bold item.
I really appreciate for ur continual help.
Ana

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract 8 Tables into 1 Large Table hewstone999 Access VBA 1 March 4th, 2008 08:19 AM
loop through tables inside .mdb file using VB.NET remya1000 General .NET 3 September 24th, 2007 12:45 PM
import data from mdb to another mdb mat41 Classic ASP Professional 3 March 9th, 2007 06:01 AM
re-link tables in a .mde when .mdb does not exist poyserr Access 1 February 22nd, 2007 11:49 AM
A query to extract part of a string RayL Access 3 March 10th, 2004 08:42 AM



All times are GMT -4. The time now is 02:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.