creating queries IN ACCESS using variables IN VB

Thread Solved

Join Date: Aug 2007
Posts: 32
Reputation: nuBudDy is an unknown quantity at this point 
Solved Threads: 0
nuBudDy nuBudDy is offline Offline
Light Poster

creating queries IN ACCESS using variables IN VB

 
0
  #1
Oct 1st, 2007
hi all, i have problem creating queries in access.this is because i do not know how to call the value from a variable in vb into the query in access.
let say in vb i've created :
Public booking_date As Date
Public fac_type As Integer
.
.
.
.
booking_date = MonthView1.value
fac_type = Combo1.ItemData

i suppose to have a query done in access which i will call in vb
SELECT TF.time_id
FROM TF
WHERE (((TF.fac_id)="fac_type") AND ((TF.reserv_date)="booking_date"));

how do i accomplish this?please help!
thanx in advnce!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: creating queries IN ACCESS using variables IN VB

 
0
  #2
Oct 1st, 2007
Originally Posted by nuBudDy View Post
hi all, i have problem creating queries in access.this is because i do not know how to call the value from a variable in vb into the query in access.
let say in vb i've created :
Public booking_date As Date
Public fac_type As Integer
.
.
.
.
booking_date = MonthView1.value
fac_type = Combo1.ItemData
i suppose to have a query done in access which i will call in vb
SELECT TF.time_id
FROM TF
WHERE (((TF.fac_id)="fac_type") AND ((TF.reserv_date)="booking_date"));
how do i accomplish this?please help!
thanx in advnce!
Hi, i've attached a sample program. download it. hope it will give you some idea.
regards
Shouvik
Attached Files
File Type: zip Access.zip (12.4 KB, 27 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 32
Reputation: nuBudDy is an unknown quantity at this point 
Solved Threads: 0
nuBudDy nuBudDy is offline Offline
Light Poster

Re: creating queries IN ACCESS using variables IN VB

 
0
  #3
Oct 3rd, 2007
thank you 4 the help choudry but what im trying to do is the reverse.instead of creating an sqlstatement in vb, i'd like to create query in access by using variables declared in vb.let say i code sql statement into query in access:
SELECT TF.time_id
FROM TF
WHERE (((TF.fac_id)="fac_type") AND ((TF.reserv_date)="booking_date"));

so when i'm done with this, i cant straight away call the query from access in vb.
the one in red is actually a variable declared in vb.
is this possible actually??
thanx in advance..
Last edited by nuBudDy; Oct 3rd, 2007 at 1:11 am. Reason: have some more information to add
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,094
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: creating queries IN ACCESS using variables IN VB

 
0
  #4
Oct 3rd, 2007
Try this
  1. select tf.time_id from tf where(((tf.rac_id= "'" fac_type & "') And ((" & tf.reserv_date)= " & booking-date & "))"
  2.  
Last edited by debasisdas; Oct 3rd, 2007 at 4:39 am.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 32
Reputation: nuBudDy is an unknown quantity at this point 
Solved Threads: 0
nuBudDy nuBudDy is offline Offline
Light Poster

Re: creating queries IN ACCESS using variables IN VB

 
0
  #5
Oct 3rd, 2007
debasisdas,
i tried but it keeps giving me a syntax error.could something be missing?do u mean to write :
fac_type as
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' " & fac_type & " '
and
booking_date as
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' " & booking_date & " '
?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: creating queries IN ACCESS using variables IN VB

 
0
  #6
Oct 4th, 2007
Originally Posted by nuBudDy View Post
debasisdas,
i tried but it keeps giving me a syntax error.could something be missing?do u mean to write :
fac_type as
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' " & fac_type & " '
and
booking_date as
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' " & booking_date & " '
?

delete the trailing spaces from both side of the sql string. the correct syntax is:-

************for fac_type************
'" & fac_type & "'

************for booking_date************
'" & booking_date & "'
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 32
Reputation: nuBudDy is an unknown quantity at this point 
Solved Threads: 0
nuBudDy nuBudDy is offline Offline
Light Poster

Re: creating queries IN ACCESS using variables IN VB

 
0
  #7
Oct 4th, 2007
i still can't get it right..i wonder is it actually possible for the query to retrieve values from variables in vb at vb run-time..
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 30
Reputation: yello is an unknown quantity at this point 
Solved Threads: 4
yello yello is offline Offline
Light Poster

Re: creating queries IN ACCESS using variables IN VB

 
0
  #8
Oct 4th, 2007
If you are writing vbcode in the MSAccess module (access macro), then you can access the variable from vb.

Also one more thing to be noted here is the data type of 'fac_type'. If it is an integer type you don't need to wrap the double quotes with single quotes
" & fac_type & " will do.
But if fac_type is a string value you need to give '" & fac_type & "'

Now, If you are writing vbcode outside access and connecting to access using ADO or DAO, I dont think you can directly access the variable from access query. The right way is to build the query in vb and pass it to access.

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 32
Reputation: nuBudDy is an unknown quantity at this point 
Solved Threads: 0
nuBudDy nuBudDy is offline Offline
Light Poster

Re: creating queries IN ACCESS using variables IN VB

 
0
  #9
Oct 7th, 2007
thank you very much for the infos.there's another thing i'm curious about.
usually,when we make an sql statement in vb,for an example :-
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Adodc1.RecordSource = SELECT * FROM Student WHERE student_id = '"& id & "'
in this case, we get a single set of information of the student(name,age,add,course,etc....).this is because the id is unique.

is it possible for "Adodc1.RecordSource" to hold more than one set of infos retrieved from the table?
eg : make a query and retrieve 3 rows of info matching the criteria of my sql statement.

*i tried doing it but keeps getting an error.i wonder if this might be the cause of my error.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 189
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

Re: creating queries IN ACCESS using variables IN VB

 
0
  #10
Oct 7th, 2007
of course adodc can hold more than one row of criteria
do you have
adodc1.refresh
after
adodc1.recordsource
????
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC