Help Please......

G

Guest

hi my code is working fine only thing is i want the newly created Sub_Modules
to assign a primary key can any help me out here is my code

On Error GoTo addfielderror
If txtmodule.Text = "" Then
MsgBox "Please Insert Module Name", vbInformation, "Adding"
txtmodule.SetFocus
Exit Sub
Else
d = FLUpper(txtmodule.Text)
que = "Insert into Modules" & "(Modules)" & " Values (" & "'" & d &
"'" & ")"
cn.Execute que
MsgBox "Record " & d & " Added to Modules.", vbInformation, "Adding"
If vbOK = 1 Then
txtmodule.Text = ""
txtmodule.SetFocus
End If
'Exit Sub
End If

Set db = OpenDatabase(App.Path & "\DB\scmregister.mdb")
'D:\VSS_WKF\SCM-VB\check\DB\scmregister.mdb")
Set tdf = db.CreateTableDef(d)

With tdf
.Fields.Append .CreateField("Sub_Modules", dbText)
db.TableDefs.Append tdf
Exit Sub
End With

addfielderror:
If Err Then
MsgBox "Module " & FLUpper(d) & " Alrady Exists", vbInformation, "Adding"
If vbOK = 1 Then
txtmodule.Text = ""
txtmodule.SetFocus
Exit Sub
ElseIf Err.Number = 3010 Then
MsgBox "Table Already Exists", vbOKOnly, "Table"
Else
MsgBox "Table " & d & " created."
End If
End If
 
S

Scott McDaniel

hi my code is working fine only thing is i want the newly created Sub_Modules
to assign a primary key can any help me out here is my code

Your Insert statement can assign a PK simply by including the correct Column name in the first part, and then including
whatever value you want in that column in the VALUES section:

INSERT INTO Modules(YourPKField, Modules) VALUES(" & YourPKValue & ",'" & d & "')

If YourPKValue is a Text value, surround it with single quotes ( ' ).

Or, you can set the YourPKField to an AutoNumber, and Access will assign the PK for you.
On Error GoTo addfielderror
If txtmodule.Text = "" Then
MsgBox "Please Insert Module Name", vbInformation, "Adding"
txtmodule.SetFocus
Exit Sub
Else
d = FLUpper(txtmodule.Text)
que = "Insert into Modules" & "(Modules)" & " Values (" & "'" & d &
"'" & ")"
cn.Execute que
MsgBox "Record " & d & " Added to Modules.", vbInformation, "Adding"
If vbOK = 1 Then
txtmodule.Text = ""
txtmodule.SetFocus
End If
'Exit Sub
End If

Set db = OpenDatabase(App.Path & "\DB\scmregister.mdb")
'D:\VSS_WKF\SCM-VB\check\DB\scmregister.mdb")
Set tdf = db.CreateTableDef(d)

With tdf
.Fields.Append .CreateField("Sub_Modules", dbText)
db.TableDefs.Append tdf
Exit Sub
End With

addfielderror:
If Err Then
MsgBox "Module " & FLUpper(d) & " Alrady Exists", vbInformation, "Adding"
If vbOK = 1 Then
txtmodule.Text = ""
txtmodule.SetFocus
Exit Sub
ElseIf Err.Number = 3010 Then
MsgBox "Table Already Exists", vbOKOnly, "Table"
Else
MsgBox "Table " & d & " created."
End If
End If

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top