My Assistant
![]() ![]() |
|
|
Feb 18 2009, 01:22 PM
Post
#1
|
|
|
UtterAccess Addict Posts: 246 |
I'm trying to use an SQL statement in the AferUpDate event of a Combo Box to fill a text box on a form.
I ran my SQL statement as a Query and it runs fine, but when I add the SQL statement to the AfterUpDate event, I get the SQL statement in my text box, not the value I'm looking for. Private Sub cboBSCID_AfterUpdate() Dim strSQl As String strSQl = "SELECT Header.PONumber, Header.BSCID FROM Header WHERE (((Header.BSCID)=[forms]![JobInfo].[cboBSCID]));" Me.txtPONumber = strSQl End Sub |
|
|
|
Feb 18 2009, 01:31 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 23,583 From: Mississippi |
Change the Row Source Type of the combo box to Table/Query.
|
|
|
|
Feb 18 2009, 02:46 PM
Post
#3
|
|
|
UtterAccess Addict Posts: 246 |
The Row Source Type of the combo box cboBSCID is Table/Query. My AfterUpdate Event is on this combo box. I'm trying to get the the value PONumber from the row that matches the cboBSCID number in the Header table into the text box txtPONUmber.
|
|
|
|
Feb 18 2009, 03:30 PM
Post
#4
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
Could you use the DLookUp() to get that single value.. eg: Me.txtPONumber = DlookUp("PONumber","Header","BSCID = "& forms!JobInfo!cboBSCID ) HTH's (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Feb 18 2009, 04:18 PM
Post
#5
|
|
|
UtterAccess Addict Posts: 246 |
I've change my form a little bit! I now want to use the SQL statement as the RecordSource for my subform(subJobInfo)
Sub SetFilter() Dim strSQL As String strSQL = "Select* From Header Where Header.[BSCID] = '" & cboBSCID & "';" Forms!JobInfo!subJobInfo.Form.RecordSource = strSQL End Sub The Code bugs on the Forms!-RecordSource line. Is it the call for the sub form recordsource or my SQl statement? |
|
|
|
Feb 18 2009, 05:09 PM
Post
#6
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
Try: CODE Dim strSQL As String strSQL = "Select * From Header Where Header.[BSCID] = '" & cboBSCID & "';" Me.subJobInfo.Form.RecordSource = strSQL (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Feb 19 2009, 09:09 AM
Post
#7
|
|
|
UtterAccess Addict Posts: 246 |
The Code still bugs on the sub form RecordSource line.
|
|
|
|
Feb 19 2009, 09:15 AM
Post
#8
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
"Bugs" or "Error" messages..!! (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Feb 20 2009, 09:42 AM
Post
#9
|
|
|
UtterAccess Addict Posts: 246 |
Run Time Error "3464"
Data type mismatch in criteria expression. |
|
|
|
Feb 20 2009, 09:47 AM
Post
#10
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
Can you place a Debug.Print after the building of the sql.. Then Ctrl-G to open up the window and view the statement and see what values are being passed.. eg: CODE Dim strSQL As String strSQL = "Select * From Header Where Header.[BSCID] = '" & cboBSCID & "';" [color="red"]Debug.Print strSQL[/color] Me.subJobInfo.Form.RecordSource = strSQL Can you confirm that Header.[BSCID] is actually is a string type..!! (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Feb 20 2009, 11:47 AM
Post
#11
|
|
|
UtterAccess Addict Posts: 246 |
Select * From Header Where Header.[BSCID] = '2';
Returned in the Immediate Window The Field BSCID is a Long Integer |
|
|
|
Feb 20 2009, 11:50 AM
Post
#12
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
So it's not a text/string type.. Ok..try: CODE Dim strSQL As String strSQL = "Select * From Header Where Header.[BSCID] = " & Me.cboBSCID Me.subJobInfo.Form.RecordSource = strSQL (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Feb 20 2009, 12:28 PM
Post
#13
|
|
|
UtterAccess Addict Posts: 246 |
the code runs, but it ask for a Parameter value for Me.cboBSCID.
|
|
|
|
Feb 20 2009, 12:33 PM
Post
#14
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
Is cboBSCID an actual control on the form..!! I was assuning it was... So I place a reference in front of the control name.. Me.cboBSCID (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Feb 20 2009, 12:39 PM
Post
#15
|
|
|
UtterAccess Addict Posts: 246 |
yes, It's the name of the ComboBox which is choosing the value. When I start typing "Me." VBA has cboBSCID as a choice.
|
|
|
|
Feb 20 2009, 12:45 PM
Post
#16
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
If it's in the list then it's in the form object list.. It should recognize the value within the selected control. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Feb 20 2009, 01:10 PM
Post
#17
|
|
|
UtterAccess Addict Posts: 246 |
I'm trying to run this code as Sub on the AfterUpdate event on the same ComboBox " cboBSCID", could this be the problem?
|
|
|
|
Feb 20 2009, 02:01 PM
Post
#18
|
|
|
UtterAccess Addict Posts: 246 |
Private Sub SetFilter()
Dim strSQL As String strSQL = "Select * From Header Where Header.[BSCID] = Forms!JobInfo.cboBSCID ;" Me.subJobInfo.Form.RecordSource = strSQL End Sub I made this change to the code, it now works, but (Always a But!) I'm not getting data for some jobs! Shouldn't this SQL select the entire row of fields where BSCID and cboBSCID are =. I'm getting all the fields or nothing! |
|
|
|
Feb 23 2009, 10:25 AM
Post
#19
|
|
|
UtterAccess Addict Posts: 246 |
I moved the code to the AfterUpdate Event Procedure and it works fine, It didn't work as a Sub Procedure.
|
|
|
|
Feb 23 2009, 11:19 AM
Post
#20
|
|
|
UtterAccess VIP Posts: 2,121 From: Lansing, MI USA |
If the combobox holds BSCID and BSCID is a number, not a string, then
CODE strSQL = "Select * From Header Where Header.[BSCID] = " & cboBSCID & ";" Note, no single quotes around the BSCID. |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 22nd May 2013 - 07:08 AM |