creating queries IN ACCESS using variables IN VB

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
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

Re: creating queries IN ACCESS using variables IN VB

 
0
  #11
Oct 7th, 2007
i had :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With Adodc2
  2. .RecordSource = "SELECT time_id FROM TF WHERE fac_id = '" & fac_type & "' AND reserv_date = '" & booking_date & "'"
  3. .Recordset.Requery*
  4. .Refresh

but i get an error that says 'object variable or with block variable not set'
and the one that gets highlighted when i debug was line*
that's why i thought the error might be before the line * which was the query;(
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 192
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
  #12
Oct 7th, 2007
what's
.recordset.requery*
for?

maybe what you need is the following
with adodc2
.recordsource =(your select statement)
.refresh
end with

do while adodc2.recordset.eof = false
'whatever you want to do with the row found
adodc2.recordset.movenext
'moves to the next row found
loop
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
  #13
Oct 7th, 2007
i tried implementing the method given but still my query returns no result.
anyone care to have a look at this problem..?i've attached my codes here..
Attached Files
File Type: zip QUERY PROBLEM.zip (12.8 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 192
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
  #14
Oct 8th, 2007
I think there are a few problems with your code. Start with this, to compare dates you should use format$
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. "SELECT time_id FROM TF WHERE fac_id = " & fac_type & " AND reserv_date = " & Format$(booking_date, "\#m\/d\/yyyy\#")

then at all the following lines change the
else
if
to elseif and then have only one endif at the end
and change all the .recordset.fields(" ") to just .recordset(" ")

If .Recordset.Fields("time_id").Value = 8 Then
Option1.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 9 Then
Option2.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 10 Then
Option3.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 11 Then
Option4.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 12 Then
Option5.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 13 Then
Option6.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 14 Then
Option7.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 15 Then
Option8.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 16 Then
Option9.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 17 Then
Option10.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 18 Then
Option11.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 19 Then
Option12.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 20 Then
Option13.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 21 Then
Option14.Enabled = False
Else
If .Recordset.Fields("time_id").Value = 22 Then
Option15.Enabled = False
Else
Option16.Enabled = False
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

what I still don't understand is what do you need
.recordset.requery
for???????
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 192
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
  #15
Oct 8th, 2007
maybe you don't have to change
.recordset.field
to just
.recordset
I just do it that way

Anyway, where in your code do you fill your datagrid?
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
  #16
Oct 8th, 2007
an addition:
i tried making queries with only one criteria which was
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. with Adodc2
  2. .RecordSource = "SELECT time_id FROM TF WHERE fac_id = " & fac_type & ""
  3. .Refresh
  4. end with
there is a result in return.it works fine.

but when i try making queries with 2 criterias
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With Adodc2
  2. .RecordSource = "SELECT time_id FROM TF WHERE fac_id = '" & fac_type & "' AND reserv_date = " & booking_date & ""
  3. .Recordset.Requery
  4. .Refresh

or using only booking_date as the criteria,it returns no result.i tried checking the datatype of booking_date from access table and variable i've declared in vb.
both are of type date.
i can't seem to find where it went wrong but for sure it has something to do with dates.

anyone who care to help,thanx x10000 in advance..
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 192
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
  #17
Oct 8th, 2007
why don't you try the select statement I wrote before, you have to use format$ in your select statement to compare dates
I tried it in your program you sent and it works, here it is again
"SELECT time_id FROM TF WHERE fac_id = " & fac_type & " AND reserv_date = " & Format$(booking_date, "\#m\/d\/yyyy\#")
Last edited by plusplus; Oct 8th, 2007 at 3:43 am.
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
  #18
Oct 8th, 2007
i got a sample program from the net that uses requery and it works fine in my login form.that's why i thought it is crucial when making queries(not knowing the real flow of it).i've altered my codes as told by you and everything went smoothly.thank you very much plusplusn also to all who had helped,thank you
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 192
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
  #19
Oct 8th, 2007
I'm happy I was able to help. You see, I just started working in vb(and programming in general) about half a year ago and my first project was a calender, all your questions sound familiar, I also had to work through them.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 70
Reputation: kehar is an unknown quantity at this point 
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: creating queries IN ACCESS using variables IN VB

 
0
  #20
Oct 8th, 2007
try with this

rs.open "select tf.time_id from tf where tf.rac_id= val('"& fac_type & "') And tf.reserv_date= cdate('" & booking-date & ")"
Reply With Quote Quick reply to this message  
Reply

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




Views: 3875 | Replies: 19
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC