|
-
Sep 4th, 2005, 11:58 PM
#1
Thread Starter
New Member
Access VBA help for a beginner
Hi
I have (am) taught myself VBA for MS Access but not real well and do not have a programming background. I hope you may be able to help...
first question... I have the following code:
Dim db As Database
Dim qrystrBookingStatus
Dim rstBookingStatus As Recordset
Dim varStatusItemStatus As String
Set db = CurrentDb
'MsgBox "varCurrentStatusField - " & varCurrentStatusField
' Check the current booking status value - true or false
qrystrBookingStatus = "select KitSent from tblBookingInfo" & _
" where BookingId = " & Chr(34) & Me.BookingId & Chr(34) & ";"
Set rstBookingStatus = db.OpenRecordset(qrystrBookingStatus, dbOpenDynaset)
varStatusItemStatus = rstBookingStatus!KitSent
rstBookingStatus.Close
----
you will notice the hardcoded field "KitSent" in the select statement.
I would like to make this code a subroutine that I can call and pass the field as a variable such as:
Dim db As Database
Dim qrystrBookingStatus
Dim rstBookingStatus As Recordset
Dim varStatusItemStatus As String
Dim fieldvariable as string
Set db = CurrentDb
'MsgBox "varCurrentStatusField - " & varCurrentStatusField
' Check the current booking status value - true or false
qrystrBookingStatus = "select " & fieldvariable & " from tblBookingInfo" & _
" where BookingId = " & Chr(34) & Me.BookingId & Chr(34) & ";"
Set rstBookingStatus = db.OpenRecordset(qrystrBookingStatus, dbOpenDynaset)
varStatusItemStatus = rstBookingStatus!fieldvariable
rstBookingStatus.Close
---
but then when I try and asign the retrieved value from the query (i.e. varStatusItemStatus = rstBookingStatus!fieldvariable) VBA does not use the value of the variable fieldvariable but takes it literally!
How do I do this?
Many thanks in advance.
MG
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|