Can you fill a text box using a query

Steve78

Registered User.
Local time
Today, 08:00
Joined
Feb 24, 2006
Messages
13
Hi, newbie needs help!

I am trying to make a courses registration database. I have 3 tables; tblContacts [ContactID], [FitstName], [LastName] [Etc..] [Etc..]
tblCourseRegistration [RegID], [ContactID] [CourseID] and tblCourses [CourseID], [RegID], [CourseName], [StartDate], [AvailablePlaces]
I have created a form called Test1 that displays The CourseID, CourseName, StartDate EndDate and an unbound textbox called PlacesLeft. I would like to display in this text box the number of places that are still available on a particular course. I've written a querie that counts the CourseID's in the course registration table this works ok but I want it to place the value in the PlacesLeft text box. Then I can do a simple calculation based on the PlacesAvailable textbox. Anyone any idea how to do this My querie reads
SELECT Count([CourseID])
FROM tblCourseRegistration
WHERE (((tblCourseRegistration.CourseID)=(Forms.Test1.CourseID)));

I tried another method which includes a command button that when clicked tries to run the following
Dim MyRS As ADODB.Recordset, strSQL As String

Set MyRS = New ADODB.Recordset
strSQL = "SELECT Count([CourseID])FROM tblCourseRegistration WHERE (((tblCourseRegistration.CourseID) = (Forms.Test1.IDNo)))"
MyRS.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

If MyRS.NoMatch Then
Me.PlacesLeft = ""
Else
Me.PlacesLeft = MyRS.Fields(0)
but Access (Ver 2000) does not like the noMatch and shows it as an error.
I would be very grateful if someone could show me how to sort this out!

Many thanks in advance
 
Last edited:
NoMatch is DAO and you are using ADO to open the RecordSet. Aside from that, you may want to look into the DCount() function.
 
Cheers for that RuralGuy the DCount() worked just Dandy!
Many thanks.
 

Users who are viewing this thread

Back
Top Bottom