473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to store my value

Hi,
This is an updated version of my earlier post, hoping to attract new readers/answers.
I want on opening my form, to check wether a field [res3] in the one-record table "programmavariabelen" is empty, and if it is, to fill it (that is of course, being the table designed to be one-record, in the first and only record) with a random integer.
This is where Zwoker has lead me to so far:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. If IsNull(DLookup("[res3]", "programmavariabelen")) Then
  4.     MsgBox "res3 is empty"
  5.     Randomize
  6.     MyTable.Open "programmavariabelen", CurrentProject.Connection, adOpenStatic, adLockOptimistic
  7.     MyTable.MoveFirst
  8.     MyTable![res3] = Rnd()
  9.     MyTable.Update
  10.     MyTable.Close
  11.  
  12. MsgBox (Me![res3])
  13. End If
  14. End Sub
It stops at My.table.open etc. , and states "object required"
Does anyone see what we overlook?
Mar 12 '08 #1
5 1407
Megalog
378 Expert 256MB
This is how I'd do it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim rs as DAO.Recordset
  3.  
  4. If IsNull(DLookup("[res3]", "programmavariabelen")) Then
  5.     MsgBox "res3 is empty"
  6.     Randomize
  7.     Set rs = CurrentDb.OpenRecordset("programmavariabelen", dbOpenDynaset)
  8.     rs.MoveFirst
  9.     rs.Edit
  10.     rs![res3] = Rnd()
  11.     rs.Update
  12.     Set rs = nothing
  13.  
  14.     MsgBox (Me![res3])
  15. End If
  16.  
  17. End Sub
Mar 12 '08 #2
This is how I'd do it:


Code: ( text )
Private Sub Form_Load()
Dim rs as DAO.Recordset

If IsNull(DLookup("[res3]", "programmavariabelen")) Then
MsgBox "res3 is empty"
Randomize
Set rs = CurrentDb.OpenRecordset("programmavariabelen", dbOpenDynaset)
rs.MoveFirst
rs.Edit
rs![res3] = Rnd()
rs.Update
Set rs = nothing

MsgBox (Me![res3])
End If

End Sub
This gives me an error in line 2: (translated from dutch its something like this:) "A datatype defined by user is not defined"
Mar 12 '08 #3
The form in question is the first one to open on opening the acces-project. Does that make any difference?
Mar 13 '08 #4
HI,

I've stripped the programlines one by one by to find out what they do (and after stripping: don't).
This is what I finaly got. And it works!
Much, much, simpler than I imagened:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load() 
  2. If IsNull(DLookup("[res3]", "programmavariabelen")) Then    
  3.     Randomize    
  4.     Me![res3] = Int(Rnd() * 10000000)   
  5.     MsgBox (Me![res3])
  6. End If 
  7. End Sub
It does exactly what I wanted it to do in the first place:
- check if res3 is empty
- then create a random number
- and store it as res3
Mar 13 '08 #5
NeoPa
32,556 Expert Mod 16PB
Nicely done.

You look as if you're having trouble finding the button that adds CODE tags. It's the # button.

Welcome to The Scripts :)
Mar 13 '08 #6

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

Similar topics

1
by: sector119 | last post by:
Hi I use optparse with callback action, my callback function return some value, but optparse does not store this value, options.callback_dest always is None. How can I store callback function...
2
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
3
by: Tony Johansson | last post by:
Hello! Assume you want to store field object that a chess board consist of. A chess board consist of 64 fields where each field is either white or black. Now to my question how should I...
12
by: turtle | last post by:
I have been reading a few topics on storing data in a table and how it is usually a bad idea. Can someone give me a clue on how to do the following: I am tracking Earned Value for my programs. ...
0
by: Harley | last post by:
I am trying to write a personal app to keep a bank balance and history. The problem I'm haveing is finding a decent way to store the data on a pocketpc under .net compact framewok useing vb.net....
3
by: Solution Seeker | last post by:
I want to Store the String value with Single Quotes in the Field of Database where if i try to Store the String value with Single Quotes (as it is) then it is throwing the error as SQL String...
2
by: bonnie.tangyn | last post by:
Hello all Would it be possible to store javascript document.forms.value to ASP session as global variable? If it is not possible, how can I pass the javascript document.forms.value to...
10
by: Brett Romero | last post by:
I'd like to store something such as the following the my app.config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="DEBUG" value="true"/> <add...
6
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
2
by: hikmaz | last post by:
I am trying to get the rightmost digits (%10) of a number (taken from the user) and store it into successive array locations and get rid of the rightmost digit (\10) to store the next and so on and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.