Load all fields name into combobox in visual basic 6.0 - visual-studio

How to load all fields name into combo box. I am using visual basic 6.0.
My code is like this.
Private Sub combo2_option()
Call Dbase
Set rs = New ADODB.Recordset
rs.Open "select ID,DATE,REFNO,SUPPLIER,MODEL,SERIAL,DESCRIPTION,UOM,CATEGORY,PUH,GDP from product_aging_monitoring ", db, 3, 3
Combo2.AddItem rs(2)
End Sub

Option 1. You can limit the records to 1 if you wish to get only the field names.
For i=0 to rs.fields.count-1
Combo2.AddItem rs.fields(i).Name
Next
Option 2 is to use ADOX (DAO) Reference instead of writing a select query. Use ADOX.Catelog object to get metadata of the tables and database

Related

Microsoft Access (mdb) : List connected Oracle tables

We are developing in Oracle ERP environment. There a quite a few view legacy MDB databases (dozens), that are connceted to Oracle views (hundreds of dependencies). In Oracle there are a custom 800+ views, that are subject to be reworked, set to deprecated and possibly will be deleted in the future.
I can see the connected Oracle DB in MDB-Design view, but I need to write those dependencies into a list. With such a list I could do software maintenance job sketched above.
I have a ADOX-based Metadata-Reader, but this does not list the oracle tables:
Public Sub ADOX_Oracle_Metadata()
'To reference ADO from Microsoft Access
'In Microsoft Access, select or create a module from the Modules tab in the Database window.
'On the Tools menu, select References....
'Verify that at least the following libraries are selected:
'
'Microsoft ActiveX Data Objects x.x Library
'ADO Ext. 2.7 for DDL and Security (ADOX)
'
Dim cn As ADODB.Connection
Dim ct As ADOX.Catalog
Dim tb As ADOX.Table
Dim strDB As String
Dim ws As Worksheet
Set cn = New ADODB.Connection
Set ct = New ADOX.Catalog
strDB = "L:\Applikationen\Access\DepreciationOutputMail.mdb"
cn.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strDB & ";"
cn.Open
Set ct.ActiveConnection = cn
For Each tb In ct.Tables
' Tables can be of type TABLE, ACCESS TABLE, SYSTEM TABLE or VIEW
Debug.Print tb.Type & " " & tb.Name
Next tb
cn.Close
Set ct = Nothing
Set cn = Nothing
End Sub
Anyhow this does not list the connected oracle tables.
Maybe I have just to change the connection string? How do I know the correct connection string? Can I read it somewhere in the computer that runs the MDB?
Can you provide a solution?
This is a screenshot of a sample situation:
The tables I need to list are marked in green.
regards, LPNO
Addon information
on request of Erik, here an extract of relevant columns of MSYSOBJECTS table, created with
SELECT MSysObjects.Connect, MSysObjects.ForeignName, MSysObjects.Name, MSysObjects.Type INTO Extract_MSYSOBJECTS
FROM MSysObjects
WHERE (((MSysObjects.Connect) Is Not Null));
Actually column NAME already lists the information I looked for. Anyhow a VBA-coding approach would still be appreciated, as there are numerous mdb databases to be checked about this.
Don't use ADOX for this, but use DAO instead.
DAO is more native to Access, and can work with linked tables more easily.
Dim db As DAO.Database
Dim td As DAO.TableDef
Set db = DBEngine.OpenDatabase("L:\Applikationen\Access\DepreciationOutputMail.mdb")
For Each td In db.TableDefs
Debug.Print td.Name; td.SourceTableName, td.Connect
Next
Do note that Access can also connect to tables/views via queries or directly from code, these wouldn't be listed. You can iterate querydefs to find the queries, but for code it would be substantially more complex.
Alternate approach using the MSysObjects table:
Dim db As DAO.Database
Set db = DBEngine.OpenDatabase("L:\Applikationen\Access\DepreciationOutputMail.mdb")
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("SELECT * FROM MSysObjects WHERE Type = 4")
Do While Not rs.EOF
Debug.Print rs!Name; rs!ForeignName
rs.MoveNext
Loop
searching around I found out that this MDB-Query does exactly what I asekd for:
SELECT MSysObjects.Name, MSysObjects.Type, MSysObjects.Flags
FROM MSysObjects
WHERE (((MSysObjects.Type)=6) AND ((MSysObjects.Flags)=2097152)) OR (((MSysObjects.Type)=1) AND ((MSysObjects.Flags)=0))
ORDER BY MSysObjects.Flags;

"Query is not understandable" - Full text searching where field types have changed

A client have a long lived IBM Notes application where someone along the line changed the type of a field from number to text.
So, now when we're trying to do an FT search like: [myField] = "1234" receive the error message: "Query is not understandable".
If I do: [myField] = 1234 it works but won't return any hits. Even though there's a document where myField = "1234".
The field is of type text in the design.
I've created a new view for testing, only allowing documents from one form.
Deleted the full text index (even on the file system)
updall -X
Fixup -r
Created full text index
In my test view I've got one column that shows if the field content being searched is of type text #IsText(myField) and all rows shows: 1 (so it's field content must be text)
None of the above worked so I created a new database copy locally.
Same problem.
Created an entirely new database (for testing only), form, view and full text index and that works.
Feels like the existing database design somewhere stores the old field type...
Any ideas appreciated.
Thanks!
/J
Datatypes and field names are stored in the UNK table. There is just one entry per field name, so it's critical not to use the same field name more than once in an application with different datatypes.
You need to rebuild the UNK table, as I blogged here http://www.intec.co.uk/full-text-search-musings/
Note, it must be an offline compact, as Duffbert says here http://www.duffbert.com/duffbert/blog.nsf/d6plinks/TDUF-5SMHV4. If anyone is in the database when you do the compact, it will fail and the UNK table will not be rebuilt.
Links are useful, but if you don't want to remove data from documents - for me such steps worked (and there was no need in removing fields from forms in designer):
Run from designer with manager access with such code inside
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim i As Integer
Dim nc As NotesNoteCollection
Dim noteid As String
Dim nextnoteid As string
Dim itemArr As Variant
Dim NeedSave As Boolean
Const ITEM_NAME = "itemName1|itemName2"
itemArr = Split( ITEM_NAME, "|" )
'погромист-кун не должен забывать про наличие итемов в формах...
Set db = s.Currentdatabase
Set nc = db.CreateNoteCollection(False)
nc.SelectForms = true
Call nc.BuildCollection
noteid = nc.Getfirstnoteid()
For i = 1 To nc.Count
Set doc = db.Getdocumentbyid( noteid )
noteid = nc.Getnextnoteid( noteid )
NeedSave = false
ForAll IA In itemArr
If doc.Hasitem( IA ) Then
Call doc.Removeitem( IA )
NeedSave = true
End If
End ForAll
If NeedSave Then
Call doc.Save( True, False )
End If
Print CStr( i ) & "\" & CStr( nc.Count )
Next
End Sub
Remove database index
Run from administrator command lo compact database.nsf -c , like mentioned in links above
Create index

How do I execute a sql statement in lotusscript if the table has a timestamp field/column?

I'm working to retrieve data from oracle 9i to lotus notes. I'm using Oracle 10g for testing since that's what I had. In the default HR database, there is an EMPLOYEES table. I've recently added a new column to get the last modified timestamp which is successful. The data is in the form like this: 25-JUL-12 10.28.32.000000 AM
The following is my lotusscript code:
Option Public
Option Declare
UseLSX "*lsxlc"
%Include "lsconst.lss"
Sub Initialize
Dim s As New NotesSession, db As NotesDatabase
Set db=s.Currentdatabase
Dim lcs As New Lcsession
lcs.Clearstatus
Dim conUser As New Lcconnection("Oracle")
Dim staffdoc As NotesDocument
Dim fieldlistuser$
fieldlistuser="EMPLOYEE_ID,FIRST_NAME,MODIFIED_AT"
conUser.Server="localhost"
conUser.UserID="hr"
conUser.Password="hr"
conUser.Connect
conUser.MetaData="HR.EMPLOYEES"
conUser.Fieldnames=fieldlistuser
Dim fieldsUser As New LCFieldList
Dim fieldUser As LCField
Call conUser.Execute("Select * From HR.EMPLOYEES", fieldsUser)
While conUser.Fetch(fieldsUser) > 0
Set staffdoc=New NotesDocument(db)
staffdoc.Form="Staff"
staffdoc.StaffID=fieldsUser.EMPLOYEE_ID(0)
staffdoc.StaffName=fieldsUser.FIRST_NAME(0)
staffdoc.DateJoin=fieldsUser.MODIFIED_AT(0)
Call staffdoc.Save(True, True)
Wend
conUser.Disconnect
End Sub
Previously everything was ok before I added the timestamp column in the EMPLOYEES table and I can export every row to a temporary lotus view. Now the error always stop at Call conUser.Execute("Select * From HR.EMPLOYEES", fieldsUser). I thought it has something to do with the line fieldlistuser="EMPLOYEE_ID,FIRST_NAME,MODIFIED_AT" so I remove MODIFIED_AT from it and commented staffdoc.DateJoin=fieldsUser.MODIFIED_AT(0) but the error still occurs. The error is Error: Invalid data type for field 'MODIFIED_AT', Connector'Oracle', Method -Execute-. Can this actually be done at all? If can, what datatype in lotus should I store the timestamp value?
My first thought is does the select statement work fine at the server?
Assuming it does, this looks like a problem with the driver converting the timestamp to a Lotus Notes datetime field. As a workaround you could create a stored procedure that returns 'modified at' as a datetime instead of a timestamp type.
Just looking at help docs and I'm wondering if captialization matters, as the LCConnection property I see listed is FieldNames, not Fieldnames.

DAO recordset with substring function

i have a vb6 application that i am using DAO to create a connection to a database and trying to open a recordset. the database is a foxpro database and i have refernece to Microsoft DAO 2.5/3.5 Compatibility Library.
my code is as follows
Dim gdbSMS As Database
If gdbSMS Is Nothing Then
Set gdbSMS = OpenDatabase("C:\Work\M2M Test\DATA", False, False, "Foxpro 2.6;")
End If
Dim sql As String
sql = "select *, substr(lineitem,8,6) as aa from shippers where shipper = '001322' order by aa"
Dim rsShipper As DAO.Recordset
Set rsShipper = gdbSMS.OpenRecordset(sql)
Do While Not rsShipper.EOF
Beep
rsShipper.MoveNext
Loop
rsShipper.Close
when i execute teh line for openrecordset i get an error "undefinied function 'substr' in expression
i run the exact same query in foxpro and it works fine. any thoughts on what i need to do to get this to work with substring functions?
thanks
Try using the T-SQL SUBSTRING function instead.
SUBSTRING ( value_expression , start_expression , length_expression )
Without using DAO recordsets, but instead using DataTables, and data adapters using OleDBProvider for Foxpro data (definitely not going back to Fox 2.x) gives you more current flexibility in querying....
That said, you could try by doing what SUBSTR() actually does... Try changing to
RIGHT( LEFT( LineItem, 14 ), 6 ) as AA

Ways to feed a report (degined by crystal reports 8.5 in vb6.0) to show a special record?

I am new to Crystal reports and now I have designed a report via Crystal reports 8.5 in vb6 and wanna to display the report.
I have picked up fields data from a View within my database but as you know Views have several records.
I want to select a special record by a Primary key which is value of a textbox on my form.
Add a parameter to the report and use the parameter in the select expert. Then, call SetParameterValue on the report document before loading.
Why not do a dynamic sql in you vb form picking the values from the textbox
strSql = "select blah from blah where blah ='" + txtBox.text +"'"
Then use then execute the query in a ado.recordset and pass that into a crystal reports application report object, using ttx files to define the data etc ...
Doing this you only have to worry about the dynamic sql from your vb form for parameter selection. The rest can be templated for any report.
Here is some code to start you off
Set AdoRs = New ADODB.Recordset
Set AdoRs = conn_rep.Execute(strSql)
Set CrRep = CrAppl.OpenReport(App.Path + "\crystal\" + CryReportName)
CrRep.Database.Tables(1).SetDataSource AdoRs, 3
CRViewer1.ReportSource = CrRep
CRViewer1.EnablePrintButton = True
CRViewer1.EnableExportButton = True
CRViewer1.EnablePrintButton = True
CRViewer1.viewReport

Resources