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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add New Method 1

Status
Not open for further replies.

WalksWithSky

Instructor
Dec 11, 2002
49
CA
Hello:

I have the following code, but it doesn't seem to do anything. I would like it to create a record in the subform for each record that shows up in the query, but the code literally does nothing -- no error messages, nothing. I was using VB Help for the source of the code.

If anyone can help, it would be greatly appreciated:

Private Sub Attendance_Enter()
Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String

Set dbs = CurrentDb
strSQL = "SELECT * FROM qryStudentClasses WHERE StudenID >0"
Set rst = dbs.OpenRecordset(strSQL)

With rst
Do Until Not .EOF
AddName rst
.MoveNext
Loop
End With

Thanks,

Walks With Sky
 
What is AddName?

Also, are you sure that Attendance_Enter is connected to the Attendance control? Sometimes controls can get disconnected from the code. The fact that there are no error messages indicates that the code isn't even running. Katie
 
Katerine:

Thanks for the response. Yeah, I kind of figured that. I was getting the 3061, too few parameters message, but fixed that problem -- and now it's not doing anything.

Addname is a function:

Code:
Function AddName(rstTemp As Recordset)

       With rstTemp
        .AddNew
        !MemberID = [MemberID]
        .Update
        .Bookmark = .LastModified
    End With

End Function

Am I on the right track here, or way off base? Thanks again.

Walks With Sky
 
Sorry, made a type in Addname -- was thinking of another database.
Code:
 With rstTemp
        .AddNew
        !StudentID = [StudentID]
        .Update
        .Bookmark = .LastModified
 End With

WWS
 
I didn't look closly at your code, so this is a shot in the dark. Me.Requery

you change the record in code that are already on the screen, It's a good idea to refreash the datapull...

Just my shot in the dark for ya.

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
It sounds like two things are going on:

[ul][li]The Attendance_Enter code is not running. In the VB editor, there should be two combo boxes at the top of the editor. The left-hand one shows the control the code is bound to. The right-hand one shows the routine name. Make sure the left-hand combo does not say "(General)"
If it does, then the code isn't bound to any event. Find the Attendance control on your form (I assume you have one), and make sure there is an "Event Procedure" indicator in the OnEnter event handler property.
[li]The code seems to be adding from the subform to the query, not the other way around. You probably want something like this:
Private Sub Attendance_Enter()
Dim dbs As Database
Dim rstQry As Recordset, rstSubform as Recordset
Dim strSQL As String

Set dbs = CurrentDb
strSQL = "SELECT * FROM qryStudentClasses WHERE StudenID >0"
Set rstQry = dbs.OpenRecordset(strSQL)
Set rstSubform = _
dbs.OpenRecordset(SubformName.Form.RecordSource)

With rstQry
Do Until .EOF
rstSubform.AddNew
rstSubform![MemberID] = ![MemberID]
rstSubform.Update

.MoveNext
Loop
End With
End Sub


Important!!! Note that, in addition to the obvious changes, I also changed "Do Until Not .EOF" to "Do Until .EOF"
[/ul] Katie
 
The Do Until Not .EOF should Do While Not .EOF.

The Do Until loop will execute until the condition is true. If the loop is encountered and the condition is already true, the loop will not be performed.

If there are records return by the SQL, when you enter the loop it is Not .EOF... the condition is true, so, it goes to the end.
 
Thanks very much for the time. I'll try that and see what happens. Again, thank you!

Walks With Sky
 
Katerine:

Thanks very much. I had to tweak the code a bit, but I got it working just fine -- couldn't have done it without your help, so thanks again!

The event handler was there, it was just my code was mixed up, just like you pointed out.

Again, thank you!

Walks With Sky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top