WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Create ADO Get and Put UDFs for Selected Database Table


#DefineFunction SchemaListTables(ConnectionStr)
   cnn = ObjectCreate("ADODB.Connection")
   cnn.Open(ConnectionStr)
   adSchemaTables = 20
   TableList     = ""
   rsSchema = cnn.OpenSchema(adSchemaTables)
   While !rsSchema.eof
;      message(rsSchema.fields("TABLE_NAME").value, rsSchema.fields("TABLE_TYPE").value)
      If rsSchema.fields("TABLE_TYPE").value == "TABLE" Then TableList = ItemInsert(rsSchema.fields("TABLE_NAME").value, -1, TableList, @TAB)
      rsSchema.movenext
   EndWhile
   rsSchema.close()
   cnn.close()
   Return(TableList)
#EndFunction

;Winbatch [Tested 2006B - should work with all versions after 2004]
;
;Create simple ADO get/put UDF's for selected Database Table
;useful for add/edit routines
;Uses Microsoft Access but could be modified to any ADO Provider
;
;The get() UDS created accepts a flag, if true it will
;initialize default variable entries
;
;Stan Littlefield, April 5, 2006
;//////////////////////////////////////////////////////////////////////////

BoxOpen("Please Wait","Creating Get/Put Subroutines")
cMDB = AskFilename( "Name of MDB file", DirScript(), "MDB Files|*.mdb", "", 1 );name of MDB
If ! FileExist(cMDB) Then Exit
cOut = StrCat(DirScript(),"UDFS.wbt")
cConn = StrCat('Provider=MicroSoft.Jet.OLEDB.4.0; Data Source="',cMDB, '"')

;tablename = AskLine( "Name of Table", "Please type the name of the Table", "") ;name of table
tablename = AskItemlist("Choose a table", SchemaListTables(cConn), @TAB, @SORTED, @SINGLE, @FALSE)

oRS = CreateObject("ADODB.Recordset")
oRS.Open(tablename,cConn,1,3,2)
cGet = StrCat("#DefineSubRoutine AdoGet(mode)",@CRLF,"If mode Then oRS.Addnew()",@CRLF)
cPut = StrCat("#DefineSubRoutine AdoPut()",@CRLF)
cInit = StrCat('cMDB = "',cMDB, '"', @CRLF)
cInit = StrCat(cInit,'If ! FileExist("', cMDB, '") Then Exit',@CRLF)
cInit = StrCat(cInit,`cConn = Strcat( 'Provider=MicroSoft.Jet.OLEDB.4.0; Data Source="',cMDB, '"')`,@CRLF)
cInit = StrCat(cInit,'oRS = CreateObject("ADODB.Recordset")',@CRLF,'oRS.Open("', tablename, '",cConn,1,3,2)',@CRLF)
cInit = StrCat(cInit,";",tablename," Table Var Init",@CRLF,"AdoGet(1)",@CRLF)
cEnd = StrCat("Return(1)",@CRLF,"#EndSubRoutine",@CRLF,@CRLF)

For i = 0 To (oRS.Fields.count)-1
   cField = oRS.Fields(i).Name
   ;to overcome WB's 28 char limit on variables
   cF1 = StrReplace(cField," ","")
   If StrLen(cF1)>27 Then cF1=StrSub(cF1,1,27)
   BoxText(cField)
   cPut = StrCat(cPut,'oRS.Fields("',cField,'").Value = c',cF1,@CRLF)
   cGet = StrCat(cGet,"c",cF1,' = oRS.Fields("',cField,'").Value',@CRLF)
Next
cGet = StrCat(cGet,"If mode Then oRS.CancelUpdate()",@CRLF)
oRS.Close()
oRS=0
FilePut(cOut,StrCat(cGet,cEnd,cPut,cEnd,@CRLF,cInit))
If FileExist(cOut)
   BoxText(StrCat("File Created: ",cOut) )
   TimeDelay(1)
EndIf
Message("Debug", "Check")
BoxShut()
Exit

Article ID:   W17110
File Created: 2007:07:03:14:28:20
Last Updated: 2007:07:03:14:28:20