943,659 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 7th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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;(
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007
Oct 7th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Oct 7th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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, 20 views)
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007
Oct 8th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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???????
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Oct 8th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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?
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Oct 8th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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..
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007
Oct 8th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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.
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Oct 8th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007
Oct 8th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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.
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Oct 8th, 2007
0

Re: creating queries IN ACCESS using variables IN VB

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 & ")"
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
kehar is offline Offline
72 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: plz help for encode
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: dynamic 2 dimensional array in vb 6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC