Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 13th, 2006, 07: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

  #2 (permalink)  
Old March 14th, 2006, 04: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

  #3 (permalink)  
Old March 14th, 2006, 08: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

  #4 (permalink)  
Old March 14th, 2006, 10: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>

  #5 (permalink)  
Old March 14th, 2006, 05: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

  #6 (permalink)  
Old March 14th, 2006, 07: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

  #7 (permalink)  
Old March 16th, 2006, 04: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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract 8 Tables into 1 Large Table hewstone999 Access VBA 1 March 4th, 2008 09: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 07:01 AM
re-link tables in a .mde when .mdb does not exist poyserr Access 1 February 22nd, 2007 12:49 PM
A query to extract part of a string RayL Access 3 March 10th, 2004 09:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.