Baffling problem, cant seem to detect the form

goldmedallist

Registered User.
Local time
Today, 15:36
Joined
Jun 24, 2005
Messages
16
I was working along a code that seemed to work fine until all of a sudden, the next time I tried it it, it doesnt. It is a simple code really as below which is giong to be the foundation for a selection followed by SQL input into the record source of another form to generate results. I get the following error message

"Microsoft Access cant find the form "Querypurpose" referred to in a Macro expression or Visual Basic Code"

It doesnt make any sense to me since, if I were to take away the " Forms!Querypurpose.RecordSource = SQL" line, than everything works fine. Did I disable any function in the VB editor cos I was playing around with rst before it happened :confused:

Would anyone be able to explain why...thanks so much!


*****
Private Sub Command59_Click()
On Error GoTo Err_Command59_Click

Dim stDocName As String
Dim SQL As String

stDocName = "Querypurpose"
SQL = "SELECT ClientInfo.ClientName FROM ClientInfo;"

Forms!Querypurpose.RecordSource = SQL
DoCmd.OpenForm stDocName, acFormDS

Exit_Command59_Click:
Exit Sub
....

***
 
I think the problem is becuse the form is not open. Try reversing the order

DoCmd.OpenForm stDocName, acFormDS
Forms!Querypurpose.RecordSource = SQL


Peter
 
Hi Peter,

Thanks for the reply. I reversed the order and it doesnt give me that error. However it does give me the error instead

"The record source "FROM..." on this form or report does not exist."

This is really wierd, since I thought my Forms!AllData.RecordSource is supposed to be modified to take on the value SQL. Here is my idea for the coding, it may be because the code is wrong that's why it doesnt work....I am posting it in case that may be the problem. I am trying to have the Recordsource changed at runtime so that it could generate the fields that are indicated using a checkbox

stDocName = "AllData"
strSQL = "SELECT DISTINCT "

With Forms!GenerateQuery
If .CheckClientName = True Then
ftrSQL = strSQL & "ClientInfo.ClientName "
End If

(truncated, there will be many checkboxes in the ideal case)

End With


ftrSQL = ftrSQL & "FROM ClientInfo ;"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Forms!AllData.RecordSource = ftrSQL

Thanks in advance for anyone's help!
 
Ok, somehow I managed to get around the problem by doing from scratch again...I am not sure why. But thanks anyway!
 

Users who are viewing this thread

Back
Top Bottom