Adding multiple records simultaneously to a table

Status
Not open for further replies.

bkitka

Registered User.
Local time
Today, 11:08
Joined
Apr 2, 2004
Messages
14
I need to add a range of records to a table based on the entry of the first record and the entry of the last record. Example: If I enter 123 as the first record and 127 as the last record, I want Access to create records for 124, 125 and 126.
 
What version of Access are you using? Open the table as a recordset and edit it using DAO or ADO code.
 
Assume table name is "NumbersBetween" and filed name "MyNumber"

Private Sub Command1_Click()
Dim intMin As Long
Dim intMax As Long
Dim ii As Integer

intMin = DMin("[MyNumber]", "NumbersBetween") + 1
intMax = DMax("[MyNumber]", "NumbersBetween") - 1
DoCmd.SetWarnings False
For ii = intMin To intMax
DoCmd.RunSQL "Insert into NumbersBetween(MyNumber) values(' " & ii & " ')"
Next
DoCmd.SetWarnings True
MsgBox "Numbers are filled!", vbExclamation, "Process completed."
End Sub
 
IgorB said:
Assume table name is "NumbersBetween" and filed name "MyNumber"

Private Sub Command1_Click()
Dim intMin As Long
Dim intMax As Long
Dim ii As Integer

intMin = DMin("[MyNumber]", "NumbersBetween") + 1
intMax = DMax("[MyNumber]", "NumbersBetween") - 1
DoCmd.SetWarnings False
For ii = intMin To intMax
DoCmd.RunSQL "Insert into NumbersBetween(MyNumber) values(' " & ii & " ')"
Next
DoCmd.SetWarnings True
MsgBox "Numbers are filled!", vbExclamation, "Process completed."
End Sub

When I do this I get and ivalid use of Null error on:intMin = DMin("[MyNumber]", "NumbersBetween") + 1

Any ideas
 
Status
Not open for further replies.

Users who are viewing this thread

Back
Top Bottom