Reference rst field from form

C

Craig

Is there a way to reference "resZip" in the following code from a form .. eg

MyFile = ![Me.cboFieldName]

where the cboFieldName = rezZip

The recordset contains one field which groups a set a set of data, in this
case a zip code. But at times it may be City, County, Country.

----------------------------------------------------------------------

Set rst2 = CurrentDb.OpenRecordset("qryGroupField")

With rst2
Do Until .EOF
Myfile = ![resZip] **(i want to change this line to a
variable from a combobox)**

Export function which runs a query based on the value of resZip and exports
a file.

..MoveNext
Loop
 
D

Dirk Goldgar

Craig said:
Is there a way to reference "resZip" in the following code from a form ..
eg

MyFile = ![Me.cboFieldName]

where the cboFieldName = rezZip

The recordset contains one field which groups a set a set of data, in this
case a zip code. But at times it may be City, County, Country.

----------------------------------------------------------------------

Set rst2 = CurrentDb.OpenRecordset("qryGroupField")

With rst2
Do Until .EOF
Myfile = ![resZip] **(i want to change this line to a
variable from a combobox)**

Export function which runs a query based on the value of resZip and
exports a file.

.MoveNext
Loop

So the name of the combo box is to come from the [resZip] field in the
recordset? If I've understood you, you could write that like this:

With rst2
' ...
MyFile = Me.Controls(![resZip])
' ...
End With

But I'm not sure if that's what you meant. If you meant it the other way
around, and instead the value of the combo box is supposed to identify which
field of the recordset you want to pull. In that case, you would write it
like this:

With rst2
' ...
MyFile = .Fields(Me.cboFieldName)
' ...
End With
 
C

Craig

Dirk Goldgar said:
Craig said:
Is there a way to reference "resZip" in the following code from a form ..
eg

MyFile = ![Me.cboFieldName]

where the cboFieldName = rezZip

The recordset contains one field which groups a set a set of data, in
this case a zip code. But at times it may be City, County, Country.

----------------------------------------------------------------------

Set rst2 = CurrentDb.OpenRecordset("qryGroupField")

With rst2
Do Until .EOF
Myfile = ![resZip] **(i want to change this line to a
variable from a combobox)**

Export function which runs a query based on the value of resZip and
exports a file.

.MoveNext
Loop

So the name of the combo box is to come from the [resZip] field in the
recordset? If I've understood you, you could write that like this:

With rst2
' ...
MyFile = Me.Controls(![resZip])
' ...
End With

But I'm not sure if that's what you meant. If you meant it the other way
around, and instead the value of the combo box is supposed to identify
which field of the recordset you want to pull. In that case, you would
write it like this:

With rst2
' ...
MyFile = .Fields(Me.cboFieldName)
' ...
End With


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)


With rst2
' ...
MyFile = .Fields(Me.cboFieldName)
' ...
End With

This is what I was looking for. It now works perfectly. I tried a number
of variations but just could not get it to work. I kept on getting the
"Item not found in this collection" message

Many, Many Thanks

Craig
 
M

Marshall Barton

Craig said:
Is there a way to reference "resZip" in the following code from a form .. eg

MyFile = ![Me.cboFieldName]

where the cboFieldName = rezZip

The recordset contains one field which groups a set a set of data, in this
case a zip code. But at times it may be City, County, Country.

----------------------------------------------------------------------

Set rst2 = CurrentDb.OpenRecordset("qryGroupField")

With rst2
Do Until .EOF
Myfile = ![resZip] **(i want to change this line to a
variable from a combobox)**

Export function which runs a query based on the value of resZip and exports
a file.

.MoveNext
Loop

Try using this kind of syntax:

Myfile = .Fields(Me.combobox)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top