help please!-Compile error: variable not defined

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a subform within a main form. Within the subform, if a user clicks on
a specific field, normally nothing happens like it should; however, if they
click on the very first column (line_item), it kicks them out of the screen
and gives the error: "compile error: variable not defined" and goes to the
row below and highlights-Contract_history. What am I doing wrong? Help
please!! I've looked at this all day with no luck. THANK YOU.

Private Sub Line_item_Click()
Dim rst_contractDetail As New ADODB.Recordset, SQLStmt As String
SQLStmt = "select contract_no,line_item,doc_type from
effective_contract_detail where contract_no = " & Me!Contract_no & " and
line_item = " & Me!Line_item
rst_contractDetail.Open SQLStmt, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
Do Until rst_contractDetail.EOF
If Not rst_contractDetail.EOF Then
contract_history.AddItem (rst_contractDetail!Contract_no & ";" &
rst_contractDetail!Line_item & ";" & rst_contractDetail!doc_type)
End If
rst_contractDetail.MoveNext
Loop
rst_contractDetail.Close
Set rst_contractDetail = Nothing
End Sub
 
Presumably contract_history is a list box or combo box on your form (or
subform).

Try Me!contract_history instead.

If that doesn't work, you may need to qualify it more correctly as

Forms!NameOfMainForm!NameOfSubformContainer.Form!contract_history

Replace NameOfMainForm with the name of the main form. Note that
NameOfSubformContainer needs to be the name of the control that's holding
the subform: that may or may not be the same name as the form being used as
the subform.
 
Doug,

Thank you so much for responding. It was a list box that had gotten deleted
from the form. Thank you for pointing me in the right direction!
 
gg said:
I have a subform within a main form. Within the subform, if a user clicks on
a specific field, normally nothing happens like it should; however, if they
click on the very first column (line_item), it kicks them out of the screen
and gives the error: "compile error: variable not defined" and goes to the
row below and highlights-Contract_history. What am I doing wrong? Help
please!! I've looked at this all day with no luck. THANK YOU.

Private Sub Line_item_Click()
Dim rst_contractDetail As New ADODB.Recordset, SQLStmt As String
SQLStmt = "select contract_no,line_item,doc_type from
effective_contract_detail where contract_no = " & Me!Contract_no & " and
line_item = " & Me!Line_item
rst_contractDetail.Open SQLStmt, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
Do Until rst_contractDetail.EOF
If Not rst_contractDetail.EOF Then
contract_history.AddItem (rst_contractDetail!Contract_no & ";" &
rst_contractDetail!Line_item & ";" & rst_contractDetail!doc_type)
End If
rst_contractDetail.MoveNext
Loop
rst_contractDetail.Close
Set rst_contractDetail = Nothing
End Sub

I am not sure what I am stating here is the norm and it may be
completely unrelated, but shouldn't an SQL end with the semicolon?

With your SQLStmt you ended it with & Me!Line_item

I am not sure what it does but I normally end mine with something like

& Me!Line_item & ";"

Just wondering.


--
Frederick Wilson

_____________________________________
for multimedia design services visit
http://www.legalanimatics.com
 
Frederick Wilson said:
I am not sure what I am stating here is the norm and it may be
completely unrelated, but shouldn't an SQL end with the semicolon?

With your SQLStmt you ended it with & Me!Line_item

I am not sure what it does but I normally end mine with something like

& Me!Line_item & ";"

Just wondering.

The semi-colon is completely optional. I find including it a nuisance, so I
never put it...
 
Back
Top