{"id":2334,"date":"2014-12-18T20:04:28","date_gmt":"2014-12-18T20:04:28","guid":{"rendered":"https:\/\/alt2.minisoft.com\/support\/?p=2334"},"modified":"2014-12-18T20:04:28","modified_gmt":"2014-12-18T20:04:28","slug":"odbc-sample-visual-basic-applications-source-code","status":"publish","type":"post","link":"https:\/\/c002.minisoft.com\/support\/odbc-sample-visual-basic-applications-source-code\/","title":{"rendered":"ODBC Sample Visual Basic Applications Source Code"},"content":{"rendered":"<p>This sample was created and used in Microsoft Access &#8217;97.<\/p>\n<p>Option Compare Database<br \/>\nOption Explicit<br \/>\nDim Db As Database<br \/>\nDim Cust As Recordset<\/p>\n<p>Sub LoadFields()<\/p>\n<p>On Error GoTo Err_LoadFields<\/p>\n<p>Text1.Value = &#8220;&#8221;<br \/>\nText2.Value = &#8220;&#8221;<br \/>\nText3.Value = &#8220;&#8221;<br \/>\nText4.Value = &#8220;&#8221;<\/p>\n<p>Text1.Value = Cust(0).Value<br \/>\nText2.Value = Cust(1).Value<br \/>\nText3.Value = Cust(&#8220;LAST_NAME&#8221;).Value<br \/>\nText4.Value = Cust(&#8220;FIRST_NAME&#8221;).Value<\/p>\n<p>Exit_LoadFields:<br \/>\nExit Sub<\/p>\n<p>Err_LoadFields:<br \/>\nIf Err.Number = 3021 Then<br \/>\nCust.MoveFirst<br \/>\nResume<br \/>\nEnd If<br \/>\nMsgBox Err.Description<br \/>\nMsgBox Err.Number<br \/>\nResume Exit_LoadFields<\/p>\n<p>End Sub<\/p>\n<p>Private Sub Form_Open(Cancel As Integer)<\/p>\n<p>Dim Connect As String<br \/>\nDim SQL As String<\/p>\n<p>On Error GoTo Err_Form_Open<\/p>\n<p>Connect$ = &#8220;ODBC;DSN=MSDB;&#8221;<br \/>\nSet Db = OpenDatabase(&#8220;&#8221;, dbDriverNoPrompt, True, Connect$)<\/p>\n<p>SQL = &#8220;SELECT * FROM CONTACTS &#8221;<br \/>\nSet Cust = Db.OpenRecordset(SQL, dbOpenDynaset)<\/p>\n<p>Cust.MoveFirst<br \/>\nLoadFields<br \/>\nExit Sub<\/p>\n<p>Err_Form_Open:<br \/>\nMsgBox Err.Description, vbCritical<br \/>\nEnd<\/p>\n<p>End Sub  <\/p>\n<p>Private Sub Command1_Click()<br \/>\nOn Error GoTo Err_Command1_Click<\/p>\n<p>Cust.MoveNext<br \/>\nIf Cust.EOF Then<br \/>\nMsgBox &#8220;EOF&#8221;<br \/>\nEnd If<br \/>\nLoadFields<\/p>\n<p>Exit_Command1_Click:<br \/>\nExit Sub<\/p>\n<p>Err_Command1_Click:<br \/>\nMsgBox Err.Description<br \/>\nResume Exit_Command1_Click<\/p>\n<p>End Sub  <\/p>\n<p>Private Sub Command2_Click()<br \/>\nOn Error GoTo Err_Command2_Click<\/p>\n<p>Cust.MovePrevious<br \/>\nIf Cust.BOF Then<br \/>\nMsgBox &#8220;BOF&#8221;<br \/>\nEnd If<br \/>\nLoadFields<\/p>\n<p>Exit_Command2_Click:<br \/>\nExit Sub<\/p>\n<p>Err_Command2_Click:<br \/>\nMsgBox Err.Description<br \/>\nResume Exit_Command2_Click<\/p>\n<p>End Sub<\/p>\n<p>Private Sub Command3_Click()<\/p>\n<p>Dim SQL As String<\/p>\n<p>On Error GoTo Err_Command3_Click<\/p>\n<p>If (Len(Text2.Value) < 1) Then\nSQL = \"SELECT * FROM CONTACTS\"\nElse\nSQL = \"SELECT * FROM CONTACTS WHERE CONTACT_NUMBER = '\" &#038; _\nFormat(Text2.Value, \"000000\") &#038; \"'\"\nEnd If\n\nSet Cust = Db.OpenRecordset(SQL, dbOpenDynaset)\nMsgBox Cust.RecordCount\nLoadFields\n\nExit_Command3_Click:\nExit Sub\n\nErr_Command3_Click:\nMsgBox Err.Description\nResume Exit_Command3_Click\n\nEnd Sub\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This sample was created and used in Microsoft Access &#8217;97. Option Compare Database Option Explicit Dim Db As Database Dim Cust As Recordset Sub LoadFields() On Error GoTo Err_LoadFields Text1.Value = &#8220;&#8221; Text2.Value = &#8220;&#8221; Text3.Value = &#8220;&#8221; Text4.Value = &#8220;&#8221; Text1.Value = Cust(0).Value Text2.Value = Cust(1).Value Text3.Value = Cust(&#8220;LAST_NAME&#8221;).Value Text4.Value = Cust(&#8220;FIRST_NAME&#8221;).Value Exit_LoadFields: Exit [&hellip;]<\/p>\n","protected":false},"author":75,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,63],"tags":[],"_links":{"self":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/2334"}],"collection":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/comments?post=2334"}],"version-history":[{"count":1,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/2334\/revisions"}],"predecessor-version":[{"id":2335,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/posts\/2334\/revisions\/2335"}],"wp:attachment":[{"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/media?parent=2334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/categories?post=2334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c002.minisoft.com\/support\/wp-json\/wp\/v2\/tags?post=2334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}