add more records at the same time

referee

Registered User.
Local time
Today, 11:17
Joined
Aug 21, 2003
Messages
38
Hi

on a form i have a begindate and enddate and e field for selecting a name

now: i want to have the following

begindate = 15/02/2008
enddate = 17/02/2008
name= test

when i press on a button i want in my table (tbltest) 3 records
with

Free name
15/02/2008 test
16/02/2008 test
17/02/2008 test

can someone help me with this code

thanks

referee
 
Psuedo:
Code:
dim lngCounter as long
dim lngStart as long
dim lngEnd as long

lngStart=clng(Startdate)
lngEnd=clng(Enddate)

for lngcounter = lngstart to lngEnd
   debug.print cdate(lngcounter) , strName
next lngCounter
Enjoy!
 
thanks for your reply

i think that i do something wrong
can je helpe me please with that attachement

thanks

referee
 

Attachments

You didn't do something wrong, it works. Just add a record in your table. The only thing you must do is change the Debug.Print statement with an insert query. i don't know where you want to put the records. It should look someting like this:
Code:
currentdb.execute "Insert into table1 (field1, field2) Values ("& cdate(lngCounter)  &","& strName &")"
Enjoy!
 
hi,
can you helpe me in the attachement
i have a problem with an error

thanks again

referee
 

Attachments

You had to dim as string and fill the variable strName = me.NAAM
You had to change the insert statement. Observe the differences.

Enjoy!
 

Attachments

Guus

thanks for your help
this is perfect

When i select can i have a message if the user already has a planning for that dates
and prevent me for add it

greetings

referee
 
Last edited:
You need to replace some code to do that.
Code:
    For lngCounter = lngStart To lngEnd
        If Len(Nz(DLookup("naam", "tblplan", "naam = '" & strName & "' and code = #" & CDate(lngCounter) & "#"), "")) > 0 Then
            MsgBox "Dit record bestaat reeds: Naam: " & strName & ", #" & CDate(lngCounter) & "#"
        Else
            CurrentDb.Execute "Insert into tblplan (naam, code) Values ('" & strName & "',#" & CDate(lngCounter) & "#)"
        End If
    Next lngCounter
Veel plezier!:D
 
guus


heel vriendelijk bedankt en groetjes uit belgie

referee
 

Users who are viewing this thread

Back
Top Bottom