By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,559 Members | 2,992 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,559 IT Pros & Developers. It's quick & easy.

Using a ComboBox lookup and a Macro

P: 26
I have created a form which has, in the form header, a combobox which looks up the values (eg. Error #) in the form and will either take the user to the record which matches the looked up value or, if the value is not found, meaning is hasn't been entered, goes to record 1. I have also created a macro through the use of a command button which, if the value is not already entered, will open a new record and prepopulate the Error# field. Apparently this isn't quite easy or clear cut enough for my users. They want some kind of message to pop up if the value isn't in the list or to have a new, blank record automatically show up.
I have tried to explain that my method, although not automatic does pretty much the same thing and means I don't spend frustrating hours trying to come up with a solution, but they still don't understand. Is there a way of making this happen? Hopefully I am being clear enough!
Jan 28 '08 #1
Share this Question
Share on Google+
2 Replies


P: 62
I have created a form which has, in the form header, a combobox which looks up the values (eg. Error #) in the form and will either take the user to the record which matches the looked up value or, if the value is not found, meaning is hasn't been entered, goes to record 1. I have also created a macro through the use of a command button which, if the value is not already entered, will open a new record and prepopulate the Error# field. Apparently this isn't quite easy or clear cut enough for my users. They want some kind of message to pop up if the value isn't in the list or to have a new, blank record automatically show up.
I have tried to explain that my method, although not automatic does pretty much the same thing and means I don't spend frustrating hours trying to come up with a solution, but they still don't understand. Is there a way of making this happen? Hopefully I am being clear enough!
If your macro calls VBA code, you can simply add a message box callout notifying the user that the record has not been found.

Expand|Select|Wrap|Line Numbers
  1. Dim dbs as DAO.Database
  2. Dim rst as DAO.Recordset
  3.  
  4. Set dbs = CurrentDb
  5. strTableName = "SELECT [YOUR_TABLE_NAME].[YOUR_FIELD_NAME] FROM [YOUR_TABLE_NAME] "
  6.  
  7. Set rst= dbs.OpenRecordset(strTableName)
  8.  
  9. If IsNull(rst![YOUR_FIELD_NAME])) Then
  10. msgbox("This record was not found in the database.")
  11. Else
  12. 'whatever you want to do if the record was found
  13. End If
  14. rst = Nothing
  15.  
  16.  
Jan 28 '08 #2

P: 26
Thanks! It worked perfectly and saved my computer from being thrown out the window.
Jan 31 '08 #3

Post your reply

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