CHR1S Posted March 7, 2013 Posted March 7, 2013 (edited) Private Sub cboCategories_2_AfterUpdate() Me!BuildingID = cbocatagories_2.Column(1) Me!Building = cbocatagories_2.Column(2) End Sub This fails with a "variable not defined" error. I'm asking it to write the values in two columns of a selection in a combo box. I'm not even sure if the above code should work as I pilfered it from another website! ha Edit - The "cbocatagories_2" is what is highlighted with the error. Edited March 7, 2013 by CHR1S
LosOjos Posted March 7, 2013 Posted March 7, 2013 Edit - The "cbocatagories_2" is what is highlighted with the error. It's a typo - cboCategories_2 PS - VBA automatically matches the capitalisation if you get the correct spelling, so if your variable name doesn't match the original in terms of capital letter placement, you know you have a typo 1
CHR1S Posted March 7, 2013 Author Posted March 7, 2013 I see the 3 hours sleep I had last night is taking its toll! Thank you @LosOjos Its now writing to the table, just the wrong things, something for me to sort tomorrow it seems
LosOjos Posted March 7, 2013 Posted March 7, 2013 Its now writing to the table, just the wrong things, something for me to sort tomorrow it seems haha, one step at a time! 1
CHR1S Posted March 7, 2013 Author Posted March 7, 2013 I may have to add "I hate Access" back to my sig!
CHR1S Posted March 8, 2013 Author Posted March 8, 2013 (edited) Data type mismatch in criteria Private Sub cboProducts_2_AfterUpdate() Me!BuildingID = cboCategories_2.Column(1) Me!Building = cboCategories_2.Column(2) Me!Assets.Building.SetFocus Me!Assets.Building.Dropdown Me!RoomID = cboProducts_2.Column(2) Me!Room = cboProducts_2.Column(1) End Sub The cascading combos work, just not the data entry. Confused Edited March 8, 2013 by CHR1S
LosOjos Posted March 8, 2013 Posted March 8, 2013 (edited) Private Sub cboProducts_2_AfterUpdate() Me!BuildingID = cboCategories_2.Column(1) Me!Building = cboCategories_2.Column(2) Me!Assets.Building.SetFocus Me!Assets.Building.Dropdown Me!RoomID = cboProducts_2.Column(2) Me!Room = cboProducts_2.Column(1) End Sub The cascading combos work, just not the data entry. Confused At a glance, do you need to add .Value to some of those? i.e. Me!BuildingID = cboCategories_2.Column(1).Value My thinking is you're trying to pass a Column object as opposed to the value held in the column... EDIT: Just checked some of my own code and that .Value is not necessary. So next step is, are you trying to pass a string to a column that only accepts integers? You can convert the string to an int with CInt, like so: Me!BuildingID = CInt(cboCategories_2.Column(1)) Edited March 8, 2013 by LosOjos 1
CHR1S Posted March 8, 2013 Author Posted March 8, 2013 (edited) Ive removed all the code, still get the error. Weird! Bound columns are correct and database is expecting a string and getting a string. Edited March 8, 2013 by CHR1S
LosOjos Posted March 8, 2013 Posted March 8, 2013 Ive removed all the code, still get the error. Weird! Very... which line is highlighted when you enter debug? 1
CHR1S Posted March 8, 2013 Author Posted March 8, 2013 Very... which line is highlighted when you enter debug? db.Execute sSQL, dbFailOnError Part of my error handling code, which worked and hasn't been changed
CHR1S Posted March 8, 2013 Author Posted March 8, 2013 Just wiped the record im using for testing and the error has gone. Not sure what was in it that it didnt like as its a combo box selection thats not changed. Weird
CHR1S Posted March 8, 2013 Author Posted March 8, 2013 Back to the issue at hand - Private Sub cboProducts_2_AfterUpdate() Me.Assets.Building = Me.cbocatagories_2.Column(1) Me.Assets.Building.SetFocus Me.Assets.Building.Dropdown Me.Assets.Room = Me!cboProducts_2.Column(2) End Sub The BuildingID and RoomID are filled correctly as they are the bound and the control source. Room and Building (their text names) are not filled in at all.
LosOjos Posted March 8, 2013 Posted March 8, 2013 What are you actually trying to do, populate entries in the database based on selections made in combo boxes? If so, it might be easier to cut out the middle man and write straight to the DB. 1
CHR1S Posted March 8, 2013 Author Posted March 8, 2013 What are you actually trying to do, populate entries in the database based on selections made in combo boxes? If so, it might be easier to cut out the middle man and write straight to the DB. To be fair, I may not even need to store that information in the table itself. I can write a query into the reports that run to poll the room and building tables and populate the values at report time.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now