Miscellaneous Visual Basic Questions and AnswersScreen/Button ManipulationsSubroutines/FunctionsAutonumber in ACCESSHow to do a query on an integer fieldDate Fields and FunctionsAnother Date MethodAdvantages/DisadvantagesHow to add the next order recordPowerPoint PresentationMsgboxSlide 12Miscellaneous Visual Basic Questions and AnswersScreen/Button Manipulations•Unload Form•Load Form•Form.Show•Form.Hide•ControlButton.Visible = True/False–cmdNextPage.Visible = True (shows the button)–cmdNextPage.Visible = False (hides the button)Subroutines/Functions•Access to variables–Form variables–Global variables–arguments passed to/from the function•Calling statement–Call functionname (arguments)•Function statement–Private Function functionname (arguments)Autonumber in ACCESS•Order number in ACCESS can be defined as autonumber•Autonumber is a “long integer”•Access will automatically increment the order number by one for each new order–Visual Basic is not so nice!How to do a query on an integer fieldDim strFind as stringDim num as Integernum = val(txtOrder.text)strFind = “[Order Number] = “ & numdatOrder.Recordset.FindFirst strFindIf datOrder.Recordset.Nomatch then msgbox (“order number: “ & txtOrder.text & “ not on file”)End IfDate Fields and Functions•lblDate.caption = Now–Now: mm-dd-yy hh:mm:ss•What if you only want part of this field–orddate = Now–lblMonth.caption = Month(orddate)–lblDay.caption = Day(orddate)–lblYear.caption = Year(orddate)–lblDate.caption = Month(orddate) & “-” & Day(orddate) & “-” Year(orddate)Another Date Method•Create a field in Access: order date–Type: Date/Time–Subtype: Short Date (mm-dd-yy)–Default: Now()•ACCESS will automatically short today’s date in the mm-dd-yy format on any records added to the ACCESS database by Visual BasicAdvantages/Disadvantages•Allowing ACCESS to insert today’s date automatically•Using functions in Visual Basic to update the fields with the dateHow to add the next order recordDim newnum as integerDim orddate as datedatOrder.Recordset.MoveLastnewnum = datOrder.Recordset.Fields (“Order Number”).value + 1datOrder.Recordset.AddnewdatOrder.Recordset.Fields (“Order Number”) = newnumdatOrder.Recordset.Fields (“Customer Id”) = txtCustID.txtorddate = now ‘date mm-dd-yy and hh:mm:ssdatOrder.Recordset.Fields(“Date of Order”) = Month(orddate) & “-” & Day(orddate) & “-” & Year(orddate)datOrder.Recordset.UpdateOmit code in brackets if default value is set in ACCESSMsgbox•MsgBox “prompt”–Default is the vbOKonly button–Same sa MsgBox (“prompt”, vbOKOnly)–MsgBox(“prompt”, VbOKOnly, “window title”)•Can display variables in the “prompt”–Msgbox (“this is a prompt ” & txtSSN.text)–MsgBox (“prompt ” & intNumber & “ the end”)Msgbox•If you want to use other buttons:–vbYesNoCancel; vbYesNo; vbRetryCancel–need to Dim Response as Integer–response = MsgBox(“prompt”, vbYesNo, “title”)•Response = 6 for Yes; 7 for no; 3 for cancel•Can combine icon and buttons:–response = MsgBox(“prompt”, vbInformation + vbYesNo, “title”)–Options for icons:•vbCritical
View Full Document