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

Text box value not recognized

Status
Not open for further replies.

Amadea

Technical User
Oct 11, 2003
49
US
In the following snippet, before Else works fine. You'll remember helping me with interating through a list box. However, after Else fails to pick up the value in Me!CRN. In other words, the new record is added, all the values are entered from the text or combo boxes as indicated except for one, Me!CRN. I cannot see what I am missing.

Could this have anything to do with the name of the text box being the same as the table field name?

'Adding or changing the instructor name
If Me!cboInstr2 <> "" And Me!cboInstr2.Column(1) <> "STAFF" Then
rs.FindFirst "Sess = '02' "
If rs.NoMatch Then
'The section is cross listed with other sections
If Me!XLst <> "" Or Not IsNull(Me!XLst) Then
For i = 0 To Me!lstCombSect.ListCount - 1
'add new record using CRNs from list box
rs.AddNew
rs!CRN = Me!lstCombSect.ItemData(i)
'add the rest of the record data from form fields
rs!InstrName = Me!cboInstr2
rs!LName = Me!cboInstr2.Column(1)
rs!FName = Me!cboInstr2.Column(2)
rs!PInd = ""
rs!Sess = "02"
rs!DivNum = Me!txtDivNum
rs!XLst = Me!XLst
rs.Update
Next i
Me!lstInstrName.Requery

'The section is not cross listed with other sections
Else
rs.AddNew
rs!CRN = Me!CRN
rs!InstrName = Me!cboInstr2
rs!LName = Me!cboInstr2.Column(1)
rs!FName = Me!cboInstr2.Column(2)
rs!PInd = ""
rs!Sess = "02"
rs!DivNum = Me!txtDivNum
rs!XLst = ""
rs.Update
Me!lstInstrName.Requery
End If
[more code after this not included here]
 
In what event does this code run?

--

"If to err is human, then I must be some kind of human!" -Me
 
Well, there is a command button that initiates this sequence of events. Based on how the user has completed data entry fields on the form, changes are made to the database tables. In this case, there is a table called InstrName that should be updated based on whether the instructor name fields onthe form are blank or not or say STAFF.

In the code above, rs.AddNew is executed but when the Else is true and executed the record is added with the CRN field blank. So it seems to me that rs.!CRN = Me!CRN is picking up a blank field. But why????

 
put a break at the rs.AddNew line then use the immediate window to check what value Me!CRN has. Also, you might want to try Me!CRN.Value or Me!CRN.Text
 
I'm with joel - use Me![CRN].Value. I often use a msgbox to pop up values when I'm testing so I can follow it through. You might find this easier than inserting a break and using the immediate window. It also helps me keep track of where I need to insert more code, or do something else, or remember where a problem is occurring.
Code:
'The section is not cross listed with other sections
        Else
            rs.AddNew
            Msgbox "CRN = " & Me!CRN.Value  ' for testing
            rs!CRN = Me!CRN
            rs!InstrName = Me!cboInstr2
        etc.
Amadea is right too - You could just comment out this if you want CRN to be blank in the record you insert. If it is picking up a value from a textbox on the form instead of the cross-reference, thats the only time you need it in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top