try this code:
In the General Declaration:
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Form_Load()
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & app.path _ & "\db.mdb;Persist Security Info=False"
In the event You want:
strSQL = "SELECT CustomerName FROM Customers WHERE CustomerCode = '" & trim(cboCustomerCode.Text) & "'"
cnn.close
cnn.open
rs.open strsql,cnn
rs.requery
text1.text=rs.fields("Customername")
Yes it is possible to have multiple Sql queries in different subs. Write the exact thing which is written in the event You want. Simply change the Sql query
Why not populate your combobox with the CustomerCode and CustomerName.
and then parse what you need and put it into the textbox
"1234-Jones"
"2345-Roberts"
"234-Davis"
VB Code:
Private Sub Combo1_KeyPress()
Dim strTex as String
strText = Me.Combo1.Text
strText = Mid(strText,Instr(strText,"-")+1)
Me.Text1.Text = strText
End Sub
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
No, I can not do that. The customer code can only be a combo box and the customer name has to be a text box.
No I understand that but I don't think you understand what I am posting take a look at the attached project:
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
Ok, I understand you Mark Gambo. But it's all right. I got it working. However, there is another thing that I need to fix.
I am now able to get the customer name and place that in the text box. My combo box does the auto-fill thingy where the user types in a letter and tries to find it in the list. How can I get the method to work (customer name into text box) only when the user has finished typing in the combo box?
Because every time I type in the combo box it gives me the customer name but if the customer name doesn't exist in the list then it gives me an error.
Ok, I understand you Mark Gambo. But it's all right. I got it working. However, there is another thing that I need to fix.
I am now able to get the customer name and place that in the text box. My combo box does the auto-fill thingy where the user types in a letter and tries to find it in the list. How can I get the method to work (customer name into text box) only when the user has finished typing in the combo box?
Because every time I type in the combo box it gives me the customer name but if the customer name doesn't exist in the list then it gives me an error.
You can either trap for the error or fire the code that gets the Customer's name on the comboboxes Lost Focus Event.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
You can either trap for the error or fire the code that gets the Customer's name on the comboboxes Lost Focus Event.
or better yet add code to the GetData Function that checks that there is a valid value in the combobox before running the query. Post your code for the Auto-Fill.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
'Doesn't run the autofill when deleting or using the backspace
If Backspaced = True Or cboCustomerCode.Text = "" Then
Backspaced = False
Exit Sub
End If
'Run through the available items and grab the first matching one.
For i = 0 To cboClustomerCode.ListCount - 1
If InStr(1, cboCustomerCode.List(i), cboCustomerCode.Text, vbTextCompare) = 1 Then
Last edited by Mark Gambo; Sep 14th, 2005 at 07:19 PM.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
I put the AutoFind function into a module so that I can use it throughout my application. I still think that you should combine the Customer Number and the Customer Name in the Combobox and then after that proper name has been selected then you strip away the customer number from the combobox and take the customer name and put it into the textbox, just my two cents.
Last edited by Mark Gambo; Jul 7th, 2005 at 05:20 AM.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."