Originally Posted by
WilsonsW
Creating a field was just an example of something I might need to do. That part isn't really the issue. The issue is performing functions that require field names. For example, if I need to update everything in a field (this is just an example), I would need to tell the query what field to update. However, the field name might be any number of things. The user will know what field it is, but will need to tell the query that information. I was thinking I could use a combo box that shows all of the fields in the table, and the user will just select the field that the action should be carried out on.
Got it. Of course you can do that. For instance, here is a short portion of a random record function that I wrote long ago:
Code:
Function RndRecord(fldInput As Variant, _
tblInput As String)
On Error GoTo Cleanup
Dim db As DAO.Database
Set db = CurrentDb
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT " & fldInput & " FROM " & tblInput, _
dbOpenDynaset)
'some code
var = rs.GetRows(rs.RecordCount)
Randomize
'array manipulations
RndRecord = var(0, 0)
End Function '//LL
So basically, the two inputs are table name and field name. Is that what you're looking for??
If so, and you always want to run an update query, you could write:
Code:
currentdb.execute _
"UPDATE " & me.combobox & " SET " & _
"[" & me.combobox2 & "] = YourUpdateValueHere " & _
"OptionalWHEREclauseHere"
combobox = tablename highlighted
combobox2 = fieldname highlighted
Does that make sense?