Sunday, December 27, 2009

Visual Basic 6.0 coding, cmdAdd_Click()?

hello everyone, I've just started learning VB 6.0. I would like to generate the primary key(unique number) automatically when a new record is added. Please help.


Private Sub cmdAdd_Click()


Dim pstLastDocNumSQL As String


Dim prslastDocNum As New ADODB.Recordset


lblDoctors.Caption = ';Add Account';


Call ClearControls '**Clear all text boxes and change the visibility of the command buttons


Call SetActiveControls


fraNavigation.Visible = False


fraFunctions.Visible = False


cmdMainMenu.Visible = False


mstMode = ';Add';


pstLastDocNumSQL = ';SELECT LastDocNum '; %26amp; _


';FROM tblSystem ';


prslastDocNum.Open pstLastDocNumSQL, gcnTDLabs, adOpenStatic, adLockOptimistic, adCmdText


txtDocNum.Text = Val(prslastDocNum!LastDocNum) + 1


txtDocNum.Locked = True


txtDocNum.BackColor = vbBlue


prslastDocNum.Close


Set prslastDocNum = Nothing


cmdSave.Visible = True


cmdCancel.Visible = True


mstDocNum = mrsDoctors.RecordCount


txtDocSurname.SetFocus


End Sub


Sub ClearControls()


txtDocNum.TextVisual Basic 6.0 coding, cmdAdd_Click()?
You have already calculated it with the line:


txtDocNum.Text = Val(prslastDocNum!LastDocNum) + 1


now you need to take the txtDocNum.Text


and use it to 'Insert' a new record in the table.

No comments:

Post a Comment