| | |
creating queries IN ACCESS using variables IN VB
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 32
Reputation:
Solved Threads: 0
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 :
i suppose to have a query done in access which i will call in vb
how do i accomplish this?please help!
thanx in advnce!
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 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 :
i suppose to have a query done in access which i will call in vbPublic booking_date As Date Public fac_type As Integer . . . . booking_date = MonthView1.value fac_type = Combo1.ItemData
how do i accomplish this?please help!SELECT TF.time_id FROM TF WHERE (((TF.fac_id)="fac_type") AND ((TF.reserv_date)="booking_date"));
thanx in advnce!
regards
Shouvik
•
•
Join Date: Aug 2007
Posts: 32
Reputation:
Solved Threads: 0
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:
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..
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
Try this
vb Syntax (Toggle Plain Text)
select tf.time_id from tf where(((tf.rac_id= "'" fac_type & "') And ((" & tf.reserv_date)= " & booking-date & "))"
Last edited by debasisdas; Oct 3rd, 2007 at 4:39 am.
Share your Knowledge.
•
•
Join Date: Aug 2007
Posts: 32
Reputation:
Solved Threads: 0
debasisdas,
i tried but it keeps giving me a syntax error.could something be missing?do u mean to write :
fac_type as and
booking_date as ?
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)
' " & fac_type & " '
booking_date as
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' " & booking_date & " '
•
•
•
•
debasisdas,
i tried but it keeps giving me a syntax error.could something be missing?do u mean to write :
fac_type asandVisual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' " & fac_type & " '
booking_date as?Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' " & 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.
Have a problem? Don't worry just give me a call and I'll fix it for you.
•
•
Join Date: Nov 2006
Posts: 30
Reputation:
Solved Threads: 4
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.
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.
•
•
Join Date: Aug 2007
Posts: 32
Reputation:
Solved Threads: 0
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 :-
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.
usually,when we make an sql statement in vb,for an example :-
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Adodc1.RecordSource = SELECT * FROM Student WHERE student_id = '"& id & "'
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.
![]() |
Similar Threads
- How do I make my Access database work with MS SQL Server? (MS Access and FileMaker Pro)
- Creating an .exe using Access (MS Access and FileMaker Pro)
- Using exisiting queries within MS Access (ASP.NET)
- How do I access variables in my queue? (C++)
- Creating data access layer in java (Java)
- problems with referring to class variables (Java)
- Error Creating Folder message during installation (OS X)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: plz help for encode
- Next Thread: dynamic 2 dimensional array in vb 6
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






