Mark O'Brien said:
Userforms in Access are a real pain.
I hate Access.
Of course they are. Access was designed specifically (perhaps inadvertantly) to ******** up the human brain when it comes to anything other than housing data and crunching it. That's why I use Access for the back end and Excel for the front end. Reports, etc... stink. Query the closed db with Excel Userform. DAO:
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Import()
<SPAN style="color:#00007F">Dim</SPAN> Cn <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>, Rs <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>, myCall <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> mySql <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, dbFullname <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, myCnt <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> myRng <SPAN style="color:#00007F">As</SPAN> Range
dbFullname = "c:\temp\db1.mdb"
myCall = "test" <SPAN style="color:#007F00">'SQL Variable</SPAN>
mySql = "SELECT [Field1], [Field2]" & _
"FROM Table1 WHERE " & _
"[Field1]=<SPAN style="color:#007F00">'" & myCall & "';" 'Stack your SQL string</SPAN>
myCall = <SPAN style="color:#00007F">Empty</SPAN> <SPAN style="color:#007F00">'Clear SQL variable string</SPAN>
<SPAN style="color:#00007F">Set</SPAN> Cn = _
CreateObject("DAO.DBEngine.36").Workspaces(0).OpenDatabase(dbFullname, , <SPAN style="color:#00007F">False</SPAN>)
<SPAN style="color:#00007F">Set</SPAN> Rs = Cn.OpenRecordset(mySql)
<SPAN style="color:#00007F">Set</SPAN> myRng = Sheets(1).[a65536].End(3)(2) <SPAN style="color:#007F00">'Destination Range</SPAN>
<SPAN style="color:#00007F">With</SPAN> Rs
myCnt = .RecordCount
<SPAN style="color:#00007F">If</SPAN> myCnt > 0 <SPAN style="color:#00007F">Then</SPAN>
.MoveLast: .MoveFirst
<SPAN style="color:#007F00">'Pull data to first sheet, cells a1:RecordestCountRow & column 2 _
2 fields in the sql pass</SPAN>
myRng.Resize(myCnt + 1, 2).CopyFromRecordset Rs
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
.<SPAN style="color:#00007F">Close</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">Set</SPAN> myRng = <SPAN style="color:#00007F">Nothing</SPAN>
Cn.<SPAN style="color:#00007F">Close</SPAN>
<SPAN style="color:#00007F">Set</SPAN> Rs = Nothing: <SPAN style="color:#00007F">Set</SPAN> Cn = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
ADO:
http://www.mrexcel.com/board2/viewtopic.php?t=53716&start=4
Are you sure your data is normalized?
I too hate Access.