Private Sub cmdINSERT_Click()
Dim rs As New ADODB.Recordset
Dim sqlstr As String
If newedit = 0 Then
sqlstr = "insert into DRUG values('" & Text1.Text & "', '" & Text2.Text & "','" & Val(Text3.Text) & "','" & Val(Text4.Text) & "','" & Text5.Text & "','" & Text6.Text & "','" & Val(Text7.Text) & "')"
rs.Open "select * from DRUG where NDCNO = '" & Text1.Text & "'", Conn, adOpenDynamic, adLockOptimistic
If rs.EOF Then
rs.Close
rs.Open sqlstr, Conn, adOpenDynamic, adLockOptimistic
MsgBox "New DRUG's Information Saved", vbInformation + vbOKOnly, "Saved"
Unload Me
Form1.Show
cleartextBOXES
Else
MsgBox "Error: Duplicate NDCNO NUMBER!", vbInformation, "ERROR"
Text1.Enabled = True
controltextboxes (True)
Text1.SetFocus
cmdedit.Enabled = False
cmdINSERT.Enabled = True
exitErr:
Exit Sub
errSave:
Conn.RollbackTrans
MsgBox "ERROR:" & Err.Description, vbCritical
Resume exitErr
End If
Else
sqlstr = "Update DRUG Set NAME_STR='" & Text2.Text & "', UNIT='" & Text3.Text & "', PKG_QTY='" & Text4.Text & "', LEGAL_CLS='" & Text5.Text & "', THERA_CLS='" & Text6.Text & "', AWP='" & Text7.Text & "', where NDCNO ='" & Text1.Text & "' "
' rs.Open sqlstr, Conn, adOpenDynamic, adLockOptimistic
'rs.Open sqlstr, Conn, adOpenDynamic, adLockOptimistic
MsgBox "Employee's Information Updated", vbInformation + vbOKOnly, "Updated"
cleartextBOXES
End If
populateFlexGrid
controltextboxes (False)
cmdINSERT.Enabled = True
End Sub
here is my table datatype
CREATE TABLE DRUG (NDCNO CHAR(5) NOT NULL PRIMARY KEY,
NAME_STR VARCHAR(30) NOT NULL,
UNIT INT(
NOT NULL,
PKG_QTY INT(
NOT NULL,
LEGAL_CLS CHAR(3) NOT NULL,
THERA_CLS CHAR(10) NOT NULL,
AWP DECIMAL(8,2) NOT NULL)