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

<<help>> Code worked before and now it doesn't!

P: n/a
I know this code has worked before but now appears to get a compile
error. The code it seems to choke on line 12.
I receive the following message and it highlights the "rst!" statement.

Error received: Microsoft Visual Basic Compile error: Type declaration
character does not match declared data type [(OK) (HELP)]

Private Sub Form_Load()

1 Dim db As Database
2 Dim rst As Recordset
3 Dim strsql As String
4 Dim idnumber As long
5 Dim firstname As String
6 Dim Lastmane As String

7 Set db = CurrentDb
8 strsql = "select [idnumber] from [workers]"
9 Set rst = db.OpenRecordset(strsql)
10 rst.MoveLast
11 rst.MoveFirst
12 idnumber = rst!("idnumber")
13 me.switchboardform = idnumber
14 rst.Close
15 Set rst = Nothing
16 Set db = Nothing

End Sub

Any ideas would be appreciated.
Thanks
Chuck

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
WCBF wrote:
I know this code has worked before but now appears to get a compile
error. The code it seems to choke on line 12.
I receive the following message and it highlights the "rst!" statement.

Error received: Microsoft Visual Basic Compile error: Type declaration
character does not match declared data type [(OK) (HELP)]

Private Sub Form_Load()

1 Dim db As Database
2 Dim rst As Recordset
3 Dim strsql As String
4 Dim idnumber As long
5 Dim firstname As String
6 Dim Lastmane As String

7 Set db = CurrentDb
8 strsql = "select [idnumber] from [workers]"
9 Set rst = db.OpenRecordset(strsql)
10 rst.MoveLast
11 rst.MoveFirst
12 idnumber = rst!("idnumber")
13 me.switchboardform = idnumber
14 rst.Close
15 Set rst = Nothing
16 Set db = Nothing

End Sub

Any ideas would be appreciated.
Thanks
Chuck

Go look at the type definition for idnumber in table workers. I will
bet it is not the same as idnumber, the variable, defined as long.

Bob
Nov 13 '05 #2

P: n/a
Try

idnumber = rst!idnumber

or

idnumber = rst.Fields("idnumber")


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"WCBF" <w0***@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I know this code has worked before but now appears to get a compile
error. The code it seems to choke on line 12.
I receive the following message and it highlights the "rst!" statement.

Error received: Microsoft Visual Basic Compile error: Type declaration
character does not match declared data type [(OK) (HELP)]

Private Sub Form_Load()

1 Dim db As Database
2 Dim rst As Recordset
3 Dim strsql As String
4 Dim idnumber As long
5 Dim firstname As String
6 Dim Lastmane As String

7 Set db = CurrentDb
8 strsql = "select [idnumber] from [workers]"
9 Set rst = db.OpenRecordset(strsql)
10 rst.MoveLast
11 rst.MoveFirst
12 idnumber = rst!("idnumber")
13 me.switchboardform = idnumber
14 rst.Close
15 Set rst = Nothing
16 Set db = Nothing

End Sub

Any ideas would be appreciated.
Thanks
Chuck

Nov 13 '05 #3

P: n/a
WCBF wrote:
I know this code has worked before but now appears to get a compile
error. The code it seems to choke on line 12.
I receive the following message and it highlights the "rst!" statement.

Error received: Microsoft Visual Basic Compile error: Type declaration
character does not match declared data type [(OK) (HELP)]

Private Sub Form_Load()

1 Dim db As Database
2 Dim rst As Recordset
3 Dim strsql As String
4 Dim idnumber As long
5 Dim firstname As String
6 Dim Lastmane As String

7 Set db = CurrentDb
8 strsql = "select [idnumber] from [workers]"
9 Set rst = db.OpenRecordset(strsql)
10 rst.MoveLast
11 rst.MoveFirst
12 idnumber = rst!("idnumber")
13 me.switchboardform = idnumber
14 rst.Close
15 Set rst = Nothing
16 Set db = Nothing

End Sub

Any ideas would be appreciated.
Thanks
Chuck

See the comment from RDWaibel

http://www.experts-exchange.com/Data..._21207636.html

" the problem, as I see it, is the ! that you have after the Rst. To
use the name of the field as teh identifier, you don't need the !. Like
so....

rst(fldName$)"
In my code I personally use the following syntax:

INrec.Fields(fldName$)
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.