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

for loop on form(Datasheetview) , need help

P: 68
I have a subform with a loop to check to make sure 1 of the values in the textbox [CallType] = "N/A" before saving, but I can't seem to finish it, , well get it just to check for 1 N/A value, here is what I have :
Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2.  
  3. Set rst = Me.CallType
  4.  
  5. Do Until .EOF
  6. rst ("CallType") <> "N/A"
  7.     .MoveNext
  8.     Set rst = Nothing
  9. Loop
  10. End With
  11.  
  12. If Me.[CallType] <> "N/A" Then Msgbox "you must have an N/A value"
  13.  
  14. End Sub
this is onclose event of form(witch is Datasheetview)
FYI: I do have a DOA referrrence
Mar 14 '08 #1
Share this Question
Share on Google+
2 Replies


Expert Mod 2.5K+
P: 2,545
Hi Trevor. There are a number of problems in your code extract, which is not going to run just yet. A skeleton that opens a table or query and checks for the value you are trying to match is listed below.
Expand|Select|Wrap|Line Numbers
  1. Dim rst as DAO.RecordSet
  2. Dim ValueFound as Boolean
  3. ValueFound = False
  4. set rst = CurrentDB.OpenRecordset("name of your query or table")
  5. Do While Not rst.EOF
  6.     ValueFound = rst![CallType] = "N/A"
  7.     rst.Movenext
  8. Loop
  9. rst.Close
  10. If ValueFound then
  11.     {do stuff}
  12. else
  13.     {do something else}
  14. endif
I guess when you say a textbox you mean a combo or a listbox. It is the recordsource for this you would need to open in the code above.

Personally, I'd use Access queries for this - which you can access using functions such as DLookup in code if you have to. The problem with taking a programmed approach is that all of the logic is hidden away from the users and maintainers of your application. Anyway, that's just my approach to it.

-Stewart
Mar 14 '08 #2

P: 68
Hi Trevor. There are a number of problems in your code extract, which is not going to run just yet. A skeleton that opens a table or query and checks for the value you are trying to match is listed below.
Expand|Select|Wrap|Line Numbers
  1. Dim rst as DAO.RecordSet
  2. Dim ValueFound as Boolean
  3. ValueFound = False
  4. set rst = CurrentDB.OpenRecordset("name of your query or table")
  5. Do While Not rst.EOF
  6.     ValueFound = rst![CallType] = "N/A"
  7.     rst.Movenext
  8. Loop
  9. rst.Close
  10. If ValueFound then
  11.     {do stuff}
  12. else
  13.     {do something else}
  14. endif
I guess when you say a textbox you mean a combo or a listbox. It is the recordsource for this you would need to open in the code above.

Personally, I'd use Access queries for this - which you can access using functions such as DLookup in code if you have to. The problem with taking a programmed approach is that all of the logic is hidden away from the users and maintainers of your application. Anyway, that's just my approach to it.

-Stewart
Stewart, I'm thinking I went about this the wrong way , so here is what I am trying to do:
I have a form in Datasheet view(to have more controle over users. The datasheet is actualy a lookup table on a form, so that I can make check values before the lookup table itself is updated the field displayed on the form (in datasheetview) is [CallType] the form name is [form1], and I need to check to make sure 1 of the values is N/A , N/A count = 0 then mesgbox 1 of the values must be N/A, if N/A count = > 1 Then msgbox only 1 N/A value is required, please make the necessisary changes.
Mar 14 '08 #3

Post your reply

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