Computer room charging system (2)

The charge system in the computer room is half developed. From blind helplessness at the beginning to being able to proceed slowly now, it is a small progress. The basic data setting window in the computer room charging system is a very important window in the whole software. When I open the database software, I see that there are many pieces of data in the corresponding table, but there should be only one piece of basic data. I guess that the latest data should be used, even if the top one is used, changing the basic data is to add a new piece of data.

Private Sub Form_Load()
   Dim txtSQL As String
   Dim mrc As ADODB.Recordset
   Dim MsgText As String
   Dim sMeg As String
   
  
    'combination SQL Sentence
   txtSQL = "SELECT top 1 *  From  BasicData_Info "
   Set mrc = ExecuteSQL(txtSQL, MsgText)
   If mrc.EOF = True Then
   MsgBox "No basic data", vbOKOnly + vbExclamation, "warning"

   Exit Sub
   Else
   txtRate.Text = mrc.Fields(0)
   txttmpRate.Text = mrc.Fields(1)
   txtunitTime.Text = mrc.Fields(2)
   txtleastTime.Text = mrc.Fields(3)
   txtPrepareTime.Text = mrc.Fields(4)
   txtlimitCash.Text = mrc.Fields(5)
   frmLogin.a = mrc.Fields(6)
   Data = mrc.Fields(7)
   Time = mrc.Fields(8)
   
   txtRate.Enabled = False
   txttmpRate.Enabled = False
   txtunitTime.Enabled = False
   txtleastTime.Enabled = False
   txtPrepareTime.Enabled = False
   txtlimitCash.Enabled = False
   
   End If
End Sub

This is the code of the whole form. The interface of the form is divided into two parts, a Frame and a series of buttons. At the beginning of entering the window, each text box in the Frame is not operable. Click Modify to modify them. Click OK to add the modified data to the database and make the enabled attribute of each text box false. Then the function of the whole window is basically completed.

Private Sub cmdOk_Click()
   Dim txtSQL As String
   Dim mrc As ADODB.Recordset
   Dim MsgText As String
   
   
            
            txtSQL = "select * from BasicData_Info "
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            
            
            If mrc.EOF = True Then
            
            MsgBox "no data", vbOKOnly + vbExclamation, "warning"

            
            Else
            
            mrc.AddNew
            'Assign value to each field
            mrc.Fields(0) = Trim(txtRate.Text)
            mrc.Fields(1) = Trim(txttmpRate.Text)
            mrc.Fields(2) = Trim(txtunitTime.Text)
            mrc.Fields(3) = Trim(txtleastTime.Text)
            mrc.Fields(4) = Trim(txtPrepareTime.Text)
            mrc.Fields(5) = Trim(txtlimitCash.Text)
            mrc.Fields(6) = Trim(frmLogin.a)
            mrc.Fields(7) = Date
            mrc.Fields(8) = Time

             'Update database
            mrc.Update
      
            'Close dataset object
            mrc.Close
            Me.Hide
            MsgBox "Basic information set successfully", vbOKOnly, "Tips"
 
      End If
This is the code for the confirm button, and also the code for adding data. The code to update the database and close the dataset must not be forgotten. Finally, it indicates that the basic information is set successfully.

Keywords: Database SQL Attribute

Added by aquilla on Wed, 06 May 2020 03:28:31 +0300