Askeladden
Programmer
I need to create New Fields in Access using VB6.0. Is ther a way I might do this? If so, how?
Thanks ahead of time.
Thanks ahead of time.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
conn.close
Set conn = Nothing
Dim Conn As ADODB.Connection
Dim Conn As ADODB.Connection
Dim LinkFelt As Long, i As Long
Dim strSQL As String
Conn.Close
Set Conn = Nothing
Set Conn = New ADODB.Connection
LinkFelt = 1
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password=;User ID=;" & _
"Data Source=c:\IKDV\Vedlikeholds_Rutiner.mdb;" & _
"Persist Security Info=True;"
Conn.Open
For i = LinkFelt - 1 To lstDocs.ListCount - 1
'set and execute SQL string
strSQL = "ALTER Table [Vedlikeholds Rutiner] ADD COLUMN Link" & LinkFelt & " Text(50)"
Conn.Execute strSQL
'To set and refresh datAccess
With datAccess
.RecordSource = strSQL
.Refresh
End With
'To Save an entry of the listbox into the newly created field
datAccess.Recordset.Fields("Link" & LinkFelt) = lstDocs.List(LinkFelt - 1)
LinkFelt = LinkFelt + 1
Next i
datasource datAccess
and
datafield txtFritekst2
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Sub Connectivity(strSQL As String)
Dim connstring As String
connstring = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password=;User ID=;" & _
"Data Source=c:\IKDV\Vedlikeholds_Rutiner.mdb;" & _
"Persist Security Info=True;"
cn.Open connstring
cn.CursorLocation = adUseClient
Debug.Print strSQL
rs.Open strSQL, cn
rs.MoveNext
If rs.EOF = True Or rs.BOF = True Then
MsgBox "Not found"
Else
Form2.Text1.Text = rs!YOUR_TBL_FIELD
'you can add extra fields in...
End If
End Sub
Connectivity ("SELECT YOUR_TBL_FIELD FROM TBL_YOUR_TABLE")
'this button as a record selector (only one way)
Private Sub Command5_Click()
Module1.rs.MoveNext
If Module1.rs.BOF = True Or Module1.rs.EOF = True Then
MsgBox "That's all of the records"
Module1.rs.Close
Module1.cn.Close
Set Module1.rs = Nothing
Set Module1.cn = Nothing
Else
Text1.Text = Module1.rs!YOUR_TBL_FIELD
Form2.Refresh
End If
End Sub
'this button alters the table
Private Sub Command6_Click()
Module1.rs.Close
Module1.cn.Close
Dim i As Long
Dim strSQL2 As String
Module1.cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password=;User ID=;" & _
"Data Source=c:\IKDV\Vedlikeholds_Rutiner.mdb;" & _
"Persist Security Info=True;"
Module1.cn.Open
For i = LinkFelt - 1 To lstDocs.ListCount - 1
strSQL2 = "ALTER Table [TBL_YOUR_TABLE] ADD COLUMN Link" & linkfelt & " Text(50)"
Module1.cn.Execute strSQL2
Linkfelt = linkfelt + 1
Next i
Module1.cn.Close
Connectivity ("SELECT YOUR_TBL_FIELD FROM TBL_YOUR_TABLE")
End Sub