Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to write a field next to each record in a table?

Status
Not open for further replies.

Spyder1000

Technical User
Nov 2, 2004
109
US
I've got a text file that I import into my database. The fields in the file are in black.

I need to write the ID next to each of the records in a series. This is indicated in red. This can be done either in Excel prior to import or in the Access table after import.
1401655d.jpg

Any ideas would be greatly appreciated.
 
Hi Spyder1000,

I had a similar problem where I needed to "copy down" a value to blank cell under it, to complete the record. Below is the code that a friend of mine assisted me with to solve this problem. I then built a macro to run this module. Works great.

Option Explicit
Option Compare Database
Function Missing_Data_New()

' Declare Local Variables
Dim strSavMyField As String ' Saved MYFIELD from previous record

Dim myConnection As ADODB.Connection ' ADO Database connection
Dim myRecordset As ADODB.Recordset ' ADO Updatable Recordset

' Handle any errors
On Error GoTo Proc_Err

' Instantiate a connection and recordset of declared type
Set myConnection = New ADODB.Connection
Set myRecordset = New ADODB.Recordset


With myConnection
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source=C:\MYDATABASE.mdb"
.Mode = adModeReadWrite
.Open
End With

myRecordset.ActiveConnection = myConnection
myRecordset.Open "MYTABLE", , adOpenDynamic, adLockOptimistic
myRecordset.MoveFirst

With myRecordset

Do While Not myRecordset.EOF

.Find "MYFIELD =" & "Null"


'If Not myRecordset.EOF Then
myRecordset.MovePrevious
strSavPatNo = myRecordset("MYFIELD")
myRecordset.MoveNext
myRecordset("MYFIELD") = strSavPatNo
'End If

myRecordset.MoveNext

Loop

End With

myRecordset.Close
Set myRecordset = Nothing
Set myConnection = Nothing

Proc_Exit:
Exit Function

Proc_Err:
MsgBox Err.Description, vbCritical
Resume Proc_Exit

End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top