hi there . tried many time on doing the project , the problem is i dnt know how to get a random data on a cell,

i need the syntax on the form_load event,

ive attached the form im workin with,

ive googled for soo many hours but cant find anything that can help me,

:'(

help pls...

Recommended Answers

All 3 Replies

sir yellow,

i have made my form work on randomizing but theres an error i dnt know

heres my the code ive made

Option Explicit
Private WithEvents conn As ADODB.Connection
Dim sql As String
Dim prov As String
Private WithEvents rs As ADODB.Recordset
Dim rCount As String
Dim cnt
Dim ID

Dim currentRR As String







Private Sub Form_Load()

Set conn = New ADODB.Connection
prov = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\MAINDB2.mdb" & ";Persist Security Info=False"
conn.open (prov), , , 0
    '"<conn string>"
 
    ' ***** (step 1) *****
 
    Set rs = conn.execute("SELECT COUNT(Question) FROM QnE")
    rCount = rs(0)
 
    ' ***** (step 2) *****
 
    Set rs = conn.execute("SELECT Question FROM QnE")
    cnt = 1
    Dim RRs
    ReDim RRs(rCount)
    Do While Not rs.EOF
        RRs(cnt) = rs(0)
        cnt = cnt + 1
        rs.movenext
    Loop
 
    ' ***** (step 3) *****
 
    Randomize
    currentRR = CLng(Rnd * rCount + 0.5)
    ID = RRs(currentRR)
 
    ' ***** (step 4) *****
 
    sql = "SELECT * FROM QnE WHERE Question=" & ID
    Set rs = conn.execute(sql)
    Label1.Caption = ID
    
    
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing
End Sub

the error that comes out when i run it is this

Syntax error (missing operator) in querry expression
'Question=(THE RANDOMED CELL DATA HERE)'

ive attach the file ive made pls check this sir

Since the variable 'ID' is a string variable you need to wrap the value with single quotes like the following.

sql = "SELECT * FROM QnE WHERE Question='" & ID &"'"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.