[RESOLVED] MSFlexGrid pls help out...!
I am developing a database application and intend purging my retrieved result on MSFlexGrid row by row but i couldnt achieve this. i need assistance on this my code looks like this.
Set TorridDbase = OpenDatabase("C:\Documents and Settings\" & GetName() & "\My Documents\MyDBase.mdb")
Set MyRecordSet = TorridDbase.OpenMyRecordSet(MyQueryString, dbOpenSnapshot)
While Not MyRecordSet.EOF
On Error Resume Next
For i = 0 To MyRecordSet.RecordCount
For j = 1 To MyRecordSet.Fields.Count
frmQuery.MSFlexGrid1.Row = i
frmQuery.MSFlexGrid1.Col =j
frmQuery.MSFlexGrid1.TextMatrix(j, i) = MyRecordSet(i).Value
MyRecordSet.MoveNext
Next
Next
Wend
pls i need your help on this project
[799 byte] By [
haggy] at [2007-11-20 9:55:57]

# 1 Re: [RESOLVED] MSFlexGrid pls help out...!
How about removing the row?
.RemoveItem .Row
(do it in reverse for more than one row)
# 2 Re: [RESOLVED] MSFlexGrid pls help out...!
I dont need to remove any row... i only want to serially populate the MSFlexGrid rows with the retrieved data on MyRecordSet... i guess i am miss-allignning the matrix method. actually i get result but not the expected... it is giving me a diagonal array whereby i want a serial array... get it ?
haggy at 2007-11-9 19:37:00 >

# 3 Re: [RESOLVED] MSFlexGrid pls help out...!
I see. Take out the On Error Resume Next, and you'll find that it gets to the end of the first record and crashes. Records that start with 0 go to -1, not the record count!
Sub ClientDisplayRecordset(x As ADODB.Recordset)
Dim rs As String, fld As String, z As Long
Dim str As String
frmClients.flx.Rows = 1
str = "^ID " & vbTab & "Last Name " & vbTab & "First Name " & vbTab
str = str & "Type " & vbTab & "Details " & vbTab
str = str & "^Amount " & vbTab
str = str & "^Start " & vbTab & "^End " & vbTab & "Length" & vbTab
str = str & "Frequency" & vbTab & "^Location " & vbTab & "^Fixed " & vbTab & "^Paid "
frmClients.flx.FormatString = str ' creates heading row above
Do While x.EOF = False
For z = 0 To x.Fields.Count - 1 ' -1 is most critical
fld = x(z) & ""
If rs <> "" Then rs = rs & vbTab
rs = rs & fld
Next z
frmClients.flx.AddItem rs
rs = ""
x.MoveNext
Loop
Set x = Nothing
End Sub
# 4 Re: [RESOLVED] MSFlexGrid pls help out...!
this is what i did actually
i wrote :
1. a subroutine that loaded all the columns in MyDBase_Mytable into a combolist
2. a subroutine that filled the fixed column of the MSFlexGrid with the Mytable column. (creates heading row)
3. I needed a subroutine that will populate the RecordSet values on the MSFlexGrid Row by Row.
Note: forget about the MSFlexGrid Columns.. i have achieved that.. i just want to populate the FlexGrid with my Recordset data in allingment with the Fixed column...
Aim: i am trying to create a flexible querying pattern such that i select an item on the combolist and input a value in a text box and i populate the result on a flexgrid. i have actually achieved everything but to populate my result perfectly on the flex grid...
i can paste all my codes on demand.
just like: SELECT * FROM MyDbase_MyTable where MyCombo.text = Mytext.value...
I think it will be more clearer now.
thanks.
NB: also i am aware of the option base 0 to end with -1, i will adjust that (thanks)
haggy at 2007-11-9 19:38:56 >

# 5 Re: [RESOLVED] MSFlexGrid pls help out...!
Tjat's exactly what I gave. It displays ANY recordset. I do the query somewhere else. I have 13 items in a drop-down, with 13 fields they can query. You said you had that part.
Do While x.EOF = False
For z = 0 To x.Fields.Count - 1 ' -1 is most critical
fld = x(z) & ""
If rs <> "" Then rs = rs & vbTab
rs = rs & fld
Next z
frmClients.flx.AddItem rs
rs = ""
x.MoveNext
Loop
# 6 Re: [RESOLVED] MSFlexGrid pls help out...!
Yeah... thanks very much... it works...
but there is one thing, pls how do i handle date object in SQL most especially when a date value is input in a textbox ?
haggy at 2007-11-9 19:41:00 >

# 7 Re: [RESOLVED] MSFlexGrid pls help out...!
Here's dates, the right way. Text uses "'" & txt & "' " Integers don't use anything in ' between & " and "
Option Explicit
Private Sub Form_Load()
Dim dteDate As Date
Dim adoRec As ADODB.Recordset
dteDate = CDate("7 March 2005 10:04:00AM")
Set adoRec = GetRecordset(dteDate)
With adoRec
Do While Not .EOF
'your code goes here
MsgBox .Fields(0)
.MoveNext
Loop
.Close
End With
Set adoRec = Nothing
End Sub
Private Function GetRecordset(ByVal pdteSearchDate As Date) As ADODB.Recordset
Dim strSQL As String
Dim adoRec As ADODB.Recordset
strSQL = "SELECT * "
strSQL = strSQL & "FROM AS_Createsched "
strSQL = strSQL & "WHERE AS_Createsched.CSIN_dates = #" & Format$(pdteSearchDate, "d mmm yyyy") & "# "
strSQL = strSQL & "AND HOUR(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "hh") & " "
strSQL = strSQL & "AND MINUTE(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "nn") & " "
Set adoRec = New ADODB.Recordset
adoRec.Open strSQL, GetConnString, adOpenForwardOnly, adLockReadOnly
Set GetRecordset = adoRec
Set adoRec = Nothing
End Function
Private Function GetConnString() As String
GetConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db4.mdb;Persist Security Info=False"
End Function
# 8 Re: [RESOLVED] MSFlexGrid pls help out...!
Thanks very much for your assistance. what i am trying to achieve is that i have a textboxt that will be used to obtain variable to be queried. i will write a function or sub to validate the value in the textbox if it is a date value IsDate()
.I want to know maybe there is a way to re-parse date value so that SQL interpreter will recognise it as date
SELECT * FROM MyDbase_MyTable where MyCombo.text = Mytext.value.
Like:
Sub ValNum()
with frmquery
Dim i As Integer
Select Case .Mytext.value
Case Is = ""
i = MsgBox("You must select a valid option from the list and enter text into the textbox", vbOKOnly, "Title")
Case IsNumeric(.Mytext.value)
.Mytext.value = CInt(.Mytext.value)
Case IsDate(.Mytext.value)
.Mytext.value = "#" & Format$(.Mytext.value , "d mmm yyyy") & "# "
Case Else
End Select
End Sub
and i will use the Mytext.value in my SQL string
is this not right...?
haggy at 2007-11-9 19:43:02 >

# 9 Re: [RESOLVED] MSFlexGrid pls help out...!
I doubt that your time/date field is formatted like that.
Try CDate() to parse into a date, or break it down like I did into hours min and sec
Plug in a test value myDate = #08/07/2007 13:21#
to get something to work.
# 10 Re: [RESOLVED] MSFlexGrid pls help out...!
thanks...i will try it
haggy at 2007-11-9 19:45:06 >

# 11 Re: [RESOLVED] MSFlexGrid pls help out...!
Create a strSQL variable and do a debug.print prior to calling it.
paste the result into Access, and try to execute it. it will tell you exactly the problem, whereas vb can't
# 12 Re: [RESOLVED] MSFlexGrid pls help out...!
actually i have tried CDate() function sometimes on Mytext.value
Case IsDate(.Mytext.value)
.Mytext.value = CDate(Mytext.value) 'or is it going to look like this ? "#" & CDate(Mytext.value) & "# "
i will work on it ..while i still rely on your guidiance.. thanks
haggy at 2007-11-9 19:47:12 >

# 13 Re: [RESOLVED] MSFlexGrid pls help out...!
hello dglienna,
i am still lost. the problem i am having is how to change the value of a variable. my code looks like this:
Dim sString As String, bstring As String, fString As string
sString = frmQuery.Combo1.Text
bstring = frmQuery.txtQuery.Text
fString = "SELECT * FROM TorrdData WHERE "
fString = fString & "[" & sString & "]"
fString = fString & "="
fString = fString & "'" & bstring & "'"
Problem: how to validate bstring to a date value if the input is a date within the query string
haggy at 2007-11-9 19:48:08 >

# 14 Re: [RESOLVED] MSFlexGrid pls help out...!
Actually i used Select Case like this
...
Select case bstring
case IsDate(bstring)
bstring = "#" & CDate(bstring) & "#"
case IsNumeric(...)
case IsNull(..)
...
but it is not seem to be working...
the "#"s are not reflecting in my debug.print view
haggy at 2007-11-9 19:49:09 >

# 15 Re: [RESOLVED] MSFlexGrid pls help out...!
Add the two last lines
fString = fString & "="
fString = fString & "'" & bstring & "'"
debug.print fString
stop
Create a qieru om Access, sql view, and paste in your code
the query should run in access and show a table of results
if not, it will tell you the problem, if it isn't obvious.
Sure they're dates and not just text?
# 16 Re: [RESOLVED] MSFlexGrid pls help out...!
yes they are dates . it seems you dont get me right.
Dim sString As String, bstring As String, fString As string
sString = frmQuery.Combo1.Text
bstring = frmQuery.txtQuery.Text
fString = "SELECT * FROM TorrdData WHERE "
fString = fString & "[" & sString & "]"
fString = fString & "="
fString = fString & "'" & bstring & "'"
Problem: how to validate bstring to a date value if the input is a date within the query string
fString = fString & "="
fString = fString & "'" & bstring & "'"
debug.print fString
stop
is there not any need to make my bstring look like this :
bstring = "#" & bstring & "#" ' for date values
i am trying to write a sub that do the following validation:
1. check the value of bstring if it is a date value
2. add "#" to both ends of bstring
Result: so that if i do debug.print , # will be attached to both ends of bstring if and only if it is a date value and look like this :
SELECT * FROM myTable WHERE myValue = #08/08/2007#
when i do debug.print i only get :
SELECT * FROM myTable WHERE myValue = '08/08/2007'
o believe it is more clearer now..
haggy at 2007-11-9 19:51:11 >

# 17 Re: [RESOLVED] MSFlexGrid pls help out...!
Hmmm. Thought you noticed from my other post.
fString = fString & "#" & bstring & "#"
we don't know what bstring is or the field in your table.
# 18 Re: [RESOLVED] MSFlexGrid pls help out...!
sincerely i have done that but not getting result.
could you sketch out how the sub will look like..?
bstring is a textbox value on my form
haggy at 2007-11-9 19:53:19 >

# 19 Re: [RESOLVED] MSFlexGrid pls help out...!
i will re-check my codes again.... than you and im very greatful
haggy at 2007-11-9 19:54:17 >

# 20 Re: [RESOLVED] MSFlexGrid pls help out...!
Forget what you're doing. Take a look at this code, and then mess around with it first.
# 21 Re: [RESOLVED] MSFlexGrid pls help out...!
hello dglienna,
thanks very much for ur assistance as it now works. actually i am the one messing things around simply because i want a structurally arranged/organised codes, and with that i am violating logics. Now that i packed some codes together, it finally worked.
once again, a big THANK YOU!
haggy at 2007-11-9 19:56:17 >

# 22 Re: [RESOLVED] MSFlexGrid pls help out...!
Had one project that had YYMMDD format all the way thru beta testing, when it was decided that 'users needed mm/dd/yy'
The whole logic used 6-digit, and he needed 8, so I gave him his field, and hid the first field.
Don't forget to use the Thread Tools to mark this as resolved!
# 23 Re: [RESOLVED] MSFlexGrid pls help out...!
how do i mark it as resolved..? i am new here..
haggy at 2007-11-9 19:58:17 >

# 24 Re: [RESOLVED] MSFlexGrid pls help out...!
scroll up to post #1, and click "Thread Tools". Scroll Down, and click "Mark as Resolved" and it will add [Resolved] to the title for you.
# 25 Re: [RESOLVED] MSFlexGrid pls help out...!
Done. Once again, thank you.
haggy at 2007-11-9 20:01:22 >

# 26 Re: [RESOLVED] MSFlexGrid pls help out...!
hello dglienna, i want to ask if it is possible to use the code to populate an opened excel sheet ?
haggy at 2007-11-9 20:02:29 >

# 27 Re: [RESOLVED] MSFlexGrid pls help out...!
hello dglienna, i want to ask if it is possible to use the code to populate an opened excel sheet ?
Sub ClientDisplayRecordset(x As ADODB.Recordset)
Dim rs As String, fld As String, z As Long
Dim str As String
frmClients.flx.Rows = 1
str = "^ID " & vbTab & "Last Name " & vbTab & "First Name " & vbTab
str = str & "Type " & vbTab & "Details " & vbTab
str = str & "^Amount " & vbTab
str = str & "^Start " & vbTab & "^End " & vbTab & "Length" & vbTab
str = str & "Frequency" & vbTab & "^Location " & vbTab & "^Fixed " & vbTab & "^Paid "
frmClients.flx.FormatString = str ' creates heading row above
Do While x.EOF = False
For z = 0 To x.Fields.Count - 1 ' -1 is most critical
fld = x(z) & ""
If rs <> "" Then rs = rs & vbTab
rs = rs & fld
Next z
frmClients.flx.AddItem rs
rs = ""
x.MoveNext
Loop
Set x = Nothing
End Sub
i`ll use automation object to load excel as in ...
dim retval
set retval = CreateObject("Application.Excel")
.....
and i`ll use retval as (excel)handle to recieve values from Recordset..
I guess it should work.
haggy at 2007-11-9 20:03:24 >

# 28 Re: [RESOLVED] MSFlexGrid pls help out...!
Start a new thread, because they have nothing to do with each other.
Once you have a rs, you can populate anything including excel.
# 29 Re: [RESOLVED] MSFlexGrid pls help out...!
ok... i`ll do that right away... thanks
haggy at 2007-11-9 20:05:33 >
