473,467 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

lookup box problem

19 New Member
Hello
I haven't done much Access work for a while and so am a bit rusty. Having a problem and hope someone can help.
I have a look-up (combo) box on a form displaying course details. The form shows courses for a specific agency - the agency is filtered as that shown on a previous form.

When using the look-up box, if a course is selected that doesn't exist for the specific agency then nothing happens - I'd really like to display a message box that says "no course available" or something - but can't figure out where to put the message box code or how to call it

so far I have

Private Sub Combo23_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[course name] = '" & Me![Combo23] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

The closest I've got to making anything happen was by putting
If rstRecordSet.EOF = False Then MsgBox "No course of this name listed for this agency" before the End Sub - but I get a run-time error which says "run-time error 424 object required"

totally out of my depth - any help appreciated

thanks
Shona
Sep 5 '07 #1
15 1508
Stwange
126 Recognized Expert New Member
Try this, it should work but I haven't tested it:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo23_AfterUpdate()
  2.     IF DCount("*","YourTableName",[course name] = '" & Me![Combo23] & "') <> 0 then 
  3.     ' Find the record that matches the control.
  4.         Dim rs As Object
  5.         Set rs = Me.Recordset.Clone
  6.         rs.FindFirst "[course name] = '" & Me![Combo23] & "'"
  7.     Else
  8.         msgbox "No course of this name listed for this agency", vbcritical, "Course not found."
  9.     End If
  10. End Sub
  11.  
Hope this helps.
Sep 5 '07 #2
shonam
19 New Member
I replaced "your table name" with "courses" - it didn't like the second " so I took it off - but afraid it still doesn't call the message box

the code I have is:

Private Sub Combo23_AfterUpdate()
If DCount("*", "courses,[course name] = '" & Me![Combo23] & "'") <> 0 Then
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[course name] = '" & Me![Combo23] & "'"
Else
MsgBox "No course of this name listed for this agency", vbCritical, "Course not found."
End If
End Sub

and this returns a run-time error: 3078 - the Microsoft Jet database engine cannot find the input table or query 'courses,[course name] = "name of the course I was looking for". Make sure it exists and that its name is spelled correctly.

many thanks
Shona
Sep 5 '07 #3
Stwange
126 Recognized Expert New Member
Try replacing it with this instead:
Expand|Select|Wrap|Line Numbers
  1. IF DCount("*","courses",[course name] = '" & Me![Combo23] & "'")
  2.  
(I missed out a " sorry, it should have had one added, not deleted)
Sep 5 '07 #4
shonam
19 New Member
thanks again - am now getting the line that starts "If Dcount ..." coming up in red and at the part [course name] = ' " the ' is highlighted and it says compile error expected expression.
sorry to be a pest

best wishes
Shona
Sep 5 '07 #5
Stwange
126 Recognized Expert New Member
sorry to be a pest
Not at all, if anything it's my fault for giving you bad code...twice. I missed out a " again! try this one:
Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "courses,"[course name] = '" & Me![Combo23] & "'") <> 0 Then
  2.  
Good luck :)
Sep 5 '07 #6
shonam
19 New Member
Fraid not - the line is red and I get compile error - syntax error when I access the combo box
thanks again
Shona
Sep 5 '07 #7
Stwange
126 Recognized Expert New Member
Fraid not - the line is red and I get compile error - syntax error when I access the combo box
thanks again
Shona
Please can you paste/rewrite the syntax error? This is getting embarrassing :)
Sep 5 '07 #8
shonam
19 New Member
That's all it says:

I click on a course in the combo box that doesn't exist for the selected agency - the screen flicks to the Visual Basic screen with the DCount row highlighted and a grey pop-up box that says :

Compile error:
Syntax error

with the yellow triangle and ! sign but no other detail

I'm really sorry
Shona
Sep 5 '07 #9
Stwange
126 Recognized Expert New Member
That's all it says:

I click on a course in the combo box that doesn't exist for the selected agency - the screen flicks to the Visual Basic screen with the DCount row highlighted and a grey pop-up box that says :

Compile error:
Syntax error

with the yellow triangle and ! sign but no other detail

I'm really sorry
Shona
I think I've seen the problem, and I swear I'm going to get it right this time:
If DCount("*", "courses","[course name] = '" & Me![Combo23] & "'") <> 0 Then

Let me know, and good luck :)
Sep 5 '07 #10
shonam
19 New Member
please don't hate me but -

compile error: expected: =

the <> is highlighted
Sep 5 '07 #11
shonam
19 New Member
IGNORE THAT - missed the If - trying again
Sep 5 '07 #12
shonam
19 New Member
well - the good news is that there isn't an error message but I'm afraid the message box doesn't appear

maybe it's just not meant to be

Have to dash off for the school run now but many thanks for all your patience and help

Shona
Sep 5 '07 #13
Stwange
126 Recognized Expert New Member
well - the good news is that there isn't an error message but I'm afraid the message box doesn't appear

maybe it's just not meant to be

Have to dash off for the school run now but many thanks for all your patience and help

Shona
No problem. I'm leaving work now anyway, I'll see if I get chance to have another look either tonight or tomorrow. If anyone else can suggest a problem in my coding, it would be helpful :)
Sep 5 '07 #14
shonam
19 New Member
Good morning - took my old Access VB book home for a bit of light reading and came up with

Private Sub Combo23_AfterUpdate()

' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[course name] = '" & Me![Combo23] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If [course name].Value <> Me![Combo23] Then
MsgBox "No course of this name listed for this agency"
End If

End Sub

and it seems to work - hurrah!!

Many, many thanks for your help yesterday

Shona
Sep 6 '07 #15
Stwange
126 Recognized Expert New Member

Many, many thanks for your help yesterday

Shona
No problem, and sorry I wasn't successful!
Sep 6 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CoreyWhite | last post by:
The future of computer architecture will use lookup tables. Currently computer processor speed outweighs the benefits of using computer memory for lookup tables, except in some cases. As computer...
1
by: James E | last post by:
I have a question about best practices of how to deal with lookup data from my C# apps. On a couple of occasions I have come across a problem where I have to automate inserting a record into a...
3
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two...
3
by: Tripp Knightly | last post by:
I have a lookup table from which I want to categorize various bands of customer net income. Some of the income is positive, some is negative. The bands vary in size (ie, <500, -200 to 0, 100 to...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
1
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard....
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
1
by: paulquinlan100 | last post by:
Hi Im having problems getting a column in one of my tables to display the lookup values correctly. The database is split, in the backend the rowsource for this particular field is set to a...
16
by: Juha Nieminen | last post by:
The so-called koenig lookup allows doing odd things like this: #include <algorithm> #include <string> int main() { std::string table; sort(table, table+10); }
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.